views:

77

answers:

1

I have a Enumerable object returned from Mongoid (MongoDB object mapper)

using HAML:

= @employees.count       
= @employees.class

- @employees.each do |e|
  =h e.inspect

the count shows 3 the class shows Enumerable::Enumerator But only 1 item is printed out

the object is returned in the controller using

@employees = Employee.limit(3).where({:_id.gte => startID.to_i})

If I change

- @employees.each do |e|

to

- @employees.to_a.each do |e|

then it prints out all 3, but why will the Enumerable method fail? If I try in rails console using p e it actually prints out 3 items.

A: 

I'm guessing that @employees is not lazy, but that it's a problem with your haml.

Try doing the equivalent of this in haml:

<ul>
= @employees.map { |e| "<li>" + e.inspect + "</li>" }.join
</ul>

Ok, just read through some haml docs, does this work for you?

- @employees.each do |e|
    %p= h e.inspect
Hitesh