ruby - Why the object returned is Enumerable? -


i don't understand why enumerable instead of object. when run code :

 - @posts.each |post|     = comment.find(id: post.id).title 

i've got error :

undefined method `title' #enumerator: comment:find({:id=>1})>

if check in console enumerator :

[2] pry(#<sinatra::application>)> comment.find 1  => #<enumerator: ...> 

i want have object #<comment @id=1 @content="great" @post_id=1>

i'm working sinatra , datamapper.

the query you're looking is:

comment.first(id: post.id).title 

which short version of:

comment.all(id: post.id).first.title 

there no find in datamapper (that know of). you're seeing result of ruby's enumerable#find: http://ruby-doc.org/core-1.9.3/enumerable.html#method-i-find, must part of datamapper objects.


Comments