I have a view that for some reason displays the memory location of the object I'm trying to loop through. I'm kinda new at rails, so I'm unsure why this is happening. The object is a note with two fields, title and content.
In the controller I have (in the index function)
@note = Note.all
Then in the vi开发者_如何学Goew I'm doing this
<%= @notes.each do |note| %>
<%= link_to note.title, "notes/#{note.id}"%>
<% end %>
The output in the browser is
School Work #Note:0x1042e4708>#Note:0x1042e2ae8>
Thanks for the help
rather than:
<%= @notes.each do |note| %>
use:
<% @notes.each do |note| %>
wrapping ruby in <%=%>
will always output something to the view, drop the equal sign (<%%>
) to simply execute ruby without outputting
精彩评论