开发者

Odd Output with Rails each loop

开发者 https://www.devze.com 2023-02-01 17:09 出处:网络
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 fi

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

0

精彩评论

暂无评论...
验证码 换一张
取 消