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

Vijai Mani
Vijai Mani
2,819 Points

Whats wrong with this code??

I am at "Updating the index page" stage in front end development section. I am using the below code within the index.html.erb file. The issue is rails is ignoring the status.name line i.e. it is not printing the name but prints "Show", "Edit" and "Delete" for each status. Could some one tell me whats wrong with the code pls ?? I have used "Status" instead of "Content" while scaffolding. Thats the only difference between what was shown on the video and what I have done

<div class="page-header"> <h1>All of the Statuses</h1> </div>

<% @statuses.each do |status| %> <div class="status"> <strong><% status.name %></strong> <div class="meta"> <%= link_to "Show", status %> <span class="admin"> <%= link_to "Edit", edit_status_path(status)%> <%= link_to "Delete", status, method: :delete, data: {confirm: "Are you sure you want to delete this status" } %> </span> </div> </div>

<% end %>

4 Answers

Vijai Mani
Vijai Mani
2,819 Points

I fixed it thanks

Brandon Barrette
Brandon Barrette
20,485 Points

You sure there are any entries that have a "name" value in the database for your status? Or are you even sure that the "name" value is being saved to the database.

In your terminal type

rails console

Then type

S = Status.last
S.name

What's the output?

Vijai Mani
Vijai Mani
2,819 Points

I am sure it is getting stored coz I am able to access the statuses using the "Show", "Edit" and "Delete" features

Tried your suggestion and I am getting the name of the person who posted the last status as the output..

Brandon Barrette
Brandon Barrette
20,485 Points

Yeah, I now see that when you said: "it's not printing status.name" Then it was because of the <%= %>. For future reference:

<% %> is ruby code that won't be displayed in the html

<%= %> is ruby code that will be displayed in the html