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 Build a Simple Ruby on Rails Application Frontend Development ERB Basics

Alan Matthews
Alan Matthews
10,161 Points

ERB basics challenge; Do not understand how to complete the challenge

Attempting to complete the challenge but I am lost on what to do. I don't understand what it is asking me. Sorry this is vague, but I don't know how to explain what I am not understanding.

1 Answer

Stone Preston
Stone Preston
42,016 Points

the initial code you are given is:

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

the above code sets up a for each loop that creates a working variable status that is available in the block. we can access that working variable status inside some embedded ruby tags. we want to access the name property of that status using name.status.

remember, since we want to insert the name into the template, we need to use erb tags that use the equals sign

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

the above code loops through every single status and prints out the name of each one

Alan Matthews
Alan Matthews
10,161 Points

Thanks for the help, that worked! Don't know why I was stumped. Feel like I have a decent grasp of the basics for Ruby, so maybe I just need to get used to Rails.

Stone Preston
Stone Preston
42,016 Points

rails and ruby are really completely different beasts. This is a good excerpt that outlines that fact from an excellent free Rails Tutorial eBook by Michael Hartl that I would recommend checking out

Rails is written in Ruby, but Rails isn’t Ruby. Some Rails classes are used like ordinary Ruby objects, but some are just grist for Rails’ magic mill. Rails is sui generis, and should be studied and understood separately from Ruby.