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

Ruby

Edward Imbat
Edward Imbat
5,350 Points

ruby on rails - loop help

Hello. I am taking the ERB Basics challenge. I am being asked to do the following: "Loop through our statuses array in an ERB template. Assume we have statuses set up as an array and want to print out the name."

This is what's given:

<% @statuses.each do |status| %> Name: <br /> <% end %>

Not sure what to do. Both prior videos do not mention loops at all.

3 Answers

Basically you need to call status.name to grab the name of the people who posted the status.

<% @statuses.each do |status| %>
Name: <%= status.name %>
<% end %>
Wayne Fonseca
Wayne Fonseca
7,796 Points

<% @statuses.each do |status| %> <br> Name: <%= status.name %> <br > <% end %> </br>

Wayne Fonseca
Wayne Fonseca
7,796 Points
<% @statuses.each do |status| %>
    Name: <%= status.name %>
  <div class="status">
<% end %>