Reputation: 21544
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 view 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
Upvotes: 3
Views: 408
Reputation: 49693
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
Upvotes: 7