views:

19

answers:

1

I have this code in my controller:

 @cats = DirCat.all

And this in a view:

  %ul#menu
    = @cats.each do |item|
      %li
        = link_to item.title, "/catalog/#{item.id}/"

And get strange output:

    <ul id='menu'>
      <li>
        <a href="/catalog/4/">hello</a>
      </li>
      <li>
        <a href="/catalog/5/">hello 1</a>
      </li>
    #<DataMapper::Collection:0x85a9d00>
    </ul>

In the irb console:

irb(main):002:0> c.each { |item| puts item.title }
hello
hello 1
=> [#<DirCat @id=4 @parent_id=1 @title="hello">, #<DirCat @id=5 @parent_id=1 @title="hello 1">]

How can I get out #<DataMapper::Collection:0x85a9d00> from my html?

+1  A: 

In HAML, = is used to display the output of a thing in your markup. #<DataMapper::Collection:0x85a9d00> is the return value of @cats.each do |item|. You want to use -, which executes code (but does not print the return value):

- @cats.each do |item|
   %li
     = link_to item.title, "/catalog/#{item.id}/"
cam
Oooops… I haven't noticed this thing. Thx a lot!
OutPunk