Why is rails dumping data per page on each

I have a simple controller called list_controller with an index that basically does

def index
    @lists = List.all
end

      

Then I have a view called index.html.haml that looks like this:

%h1 My lists
= @lists.each do |list|
    .row-fluid
        %h2= list.title
        %p= list.description
%hr
= link_to "New list", new_list_url

      

This works and displays, but the ruby ​​print of list objects appears at the bottom of my list, good big ugliness in this case:

[#<List id: 1, title: "Petes todo list", description: "This is petes main list, all sorts of good stuff", created_at: "2012-03-26 21:42:57", updated_at: "2012-03-26 21:42:57">, #<List id: 2, title: "Petes work list", description: "A list for petes work stuff", created_at: "2012-03-26 22:09:50", updated_at: "2012-03-26 22:09:50">]

      

Why is this happening? How can I stop it?

+3


source to share


2 answers


You output the result each

, change:

= @lists.each do |list|

      

in



- @lists.each do |list|

      


Haml documentation: =

vs-

+3


source


= @lists.each do |list|

tells Haml to evaluate the Ruby code on the right and then print the return value. You must rewrite your view on



%h1 My lists
- @lists.each do |list|
    .row-fluid
        %h2= list.title
        %p= list.description
%hr
= link_to "New list", new_list_url

      

+1


source







All Articles