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 trialAshley Schneider
7,627 PointsERB Basics code challenge help
The code challenge is asking to "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." and the code in place is:
<% @statuses.each do |status| %>
Name: <br />
<% end %>
I understand what the challenge is asking for, I just don't understand what to put down.
9 Answers
Joseph Hall
10,865 Pointsremember to use the output erb tags <%= status.name %>.
Jason Seifer
Treehouse Guest TeacherHey Ashley! Here's a hint: try putting some ERB output for the "status.name" on the second line.
Michael Hall
Courses Plus Student 30,909 Pointsthe "Name:" is getting put into the html. It just gets printed to the screen. So when we call each on the statuses array, we pull each index one at a time and set that index to "status". .name is a method. So, if each status is a hash then the name method would be looking for the key :name and returning that value. status.name so, in the end this would print out something like
Name: "Jim"
Ashley Schneider
7,627 PointsFigured it out, thanks so much!
Jason Seifer
Treehouse Guest TeacherAwesome! Let us know if you need any more help :)
jay whitley
Courses Plus Student 7,293 Pointsi need help with this one, i'm a newbie, been stuck on it for like 4 hours!! no joke
Ashley Schneider
7,627 PointsJust do what Joseph and Jason said and use the erb output tags <%= status.name %>
Micah Goldston
5,014 PointsVery green here. So "Name: <br />" is representative of an array in Ruby?
Kingsley Ijomah
Courses Plus Student 648 Points@Micah Goldston I think "Name" is just a label, the magic happens in "<%=" which does 2 things, the "<%" we are about to write a ruby code, then "=" says print this out to the screen.
The "status.name" is then saying something like go into "status" object and get an attribute defined which is called "name".
So I don't think there is an array used at all.
If you want to see what the structure of status looks like then do something like this: <%= status.inspect %>
Louis Magnotti
4,402 PointsI didn't get how to what the 'Name' was all about either. Just remember <%= status.name %> and you will be all good!