On 28 June 2011 18:10, John Merlino <stoicism1@aol.com> wrote:
> available_books = books.each.map do |book|
> book.subbooks.where(:book_state_id =>
> BookState[:available_for_assignment].id)
> end
>
> available_books.flatten.map(&:sequence).min
>
> "undefined method sequence for 1:Fixnum"
>
> produces the above error. It's this part "map(&:sequence).min" that is
> causing it. Basically I am flattening the array of subbooks and then
> searching the one which has the lowest value for the sequence
> attribute, corresponding to a sequence field in the subbooks table.
The problem is that the "array of subbooks" isn't an array of
subbooks, it's an array of something which includes some integers.
Hence, when you iterate it, you get an undefined method for Integer.
I would be inspecting the available_books array in debug (or the
console) and seeing what it really consists of.
BTW, I'd also suggest that the whole "get_for_assignment" method could
be achieved by a scope with the appropriate conditions...
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment