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

ERB 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
Joseph Hall
10,865 Points

remember to use the output erb tags <%= status.name %>.

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Hey Ashley! Here's a hint: try putting some ERB output for the "status.name" on the second line.

Michael Hall
PLUS
Michael Hall
Courses Plus Student 30,909 Points

the "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"

Figured it out, thanks so much!

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Awesome! Let us know if you need any more help :)

i need help with this one, i'm a newbie, been stuck on it for like 4 hours!! no joke

Just do what Joseph and Jason said and use the erb output tags <%= status.name %>

Micah Goldston
Micah Goldston
5,014 Points

Very green here. So "Name: <br />" is representative of an array in Ruby?

@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 %>

I didn't get how to what the 'Name' was all about either. Just remember <%= status.name %> and you will be all good!