Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Lut Garcia
3,631 PointsBuild a simple RoR App Challenge - Show all users
I am following the Build a Simple Ruby on Rails Application project and have the following question.
How would you do an index.html page to show all the registered users??
1 Answer
Nick Fuller
9,027 PointsI cannot remember this project very well but in the index action (or method) of your controller you would assign an instance variable like
def index
@users = User.all
end
Next, in your template (index.html.erb), you can access the @users instance variable and loop through the collection returned by ActiveRecord
<ul>
<% @users.each do |user| %>
<li><%= user.email %></li>
<% end %>
</ul>