3

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

1 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.