hmmm, this returns true as well:
logger.info "is true? #{available_books.flatten.first.respond_to?
('sequence')}"
On Jun 28, 3:22 pm, John Merlino <stoici...@aol.com> wrote:
> Thanks for response. I checked with logger and it is indeed an array:
>
> logger.info "Is array? #{available_books.flatten.is_a?(Array)}"
> #outputs: true
>
> It's an array of subbook objects:
> <Subbook:0x10bef7de0>#<Subbook:0x10bef7ca0>#<Subbook:
> 0x10bef7bb0>#<Subbook:0x10bef7ae8>#<Subbook:0x10bec0ed0>#<Subbook:
> 0x10bec0db8>#<Subbook:0x10bec0cc8>#<Subbook:0x10bec0840>#<Subbook:
> 0x10bea9140>#<Subbook:0x10bea8fd8>#<Subbook:0x10bea8e70>#<Subbook:
> 0x10bea8c90>#<Subbook:0x10be8a998>#<Subbook:0x10be8a678>#<Subbook:
> 0x10be8a268>#<Subbook:0x10be86c80>#<Subbook:0x10be780e0>#<Subbook:
> 0x10be78018>#<Subbook:0x10be77f28>#<Subbook:0x10be77e88>#<Subbook:
> 0x10be69b58>#<Subbook:0x10be69ab8>#<Subbook:0x10be699a0>#<Subbook:
> 0x10be698d8>#<Subbook:0x10be63d98>#<Subbook:0x10be63cf8>#<Subbook:
> 0x10be63b90>#<Subbook:0x10be63af0>#<Subbook:0x10be5d3d0>#<Subbook:
> 0x10be5cd90>#<Subbook:0x10be5c4f8>#<Subbook:0x10be5c3e0>#<Subbook:
> 0x10be53768>#<Subbook:0x10be53420>#<Subbook:0x10be532e0>#<Subbook:
> 0x10be531f0>#<Subbook:0x10be46180>#<Subbook:0x10be45e88>#<Subbook:
> 0x10be45ac8>#<Subbook:0x10be45960>
>
> Now when I look at above, it appears to reference the class itself,
> and since Active Record converts fields to instance methods, the class
> itself doesn't have access to the sequence instance method, only
> instances of the class.
>
> Is this the problem and how would I address it?
>
> Thanks for response
>
> On Jun 28, 1:34 pm, Michael Pavling <pavl...@gmail.com> wrote:
>
>
>
>
>
>
>
> > On 28 June 2011 18:10, John Merlino <stoici...@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