Hello all, Can anyone clear this up for me?... Example: 1 table, 1 record in table>>result = Stuff.find(:all)>>result.size=> 1>>result = Stuff.find(1)>>result.sizeNoMethodError: undefined method `size''...blah blah>>result = Stuff.find(:all, :conditions => ''id =1'')>>result.size=> 1 ...I''m having troubles understanding this relationship (unless it''s a bug?) and it''s making it very frustrating if I want to use the same view to show a single or many records. I can get around it by using the :conditions as stated above but should I have to? Using...>>result.countNoMethodError: undefined method `count''...blah blah ...seems to have the same issues. Can anyone shed some light on this? Sorry if it''s already been covered somewhere else I didn''t know how to exactly phrase my question without having to read through a hundred posts. Thanks! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, Model.find(:all) will return an array of results, even if there is only one matching record. So, in your example: result = Stuff.find(:all, :conditions => ''id =1'') Here, result is actually an array of 1 item. The ''size'' method is a method of the Array class in ruby, and will only work when the Model.find call returns an array. So, as in your example again: result = Stuff.find(1) Here, result is simply an instance of the ''Stuff'' class (i.e. the record with id=1). Therefore the ''size'' method will not work because it is not a method of the ''Stuff'' class. Hope that helps. ~ Mark -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yes! ...it does seem awkward to have to account for this in a separate way especially when rails is so great in other ways. :) Thank you, Chris On Sep 7, 7:10 pm, Mark Dodwell <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > > Model.find(:all) will return an array of results, even if there is only > one matching record. > > So, in your example: > > result = Stuff.find(:all, :conditions => ''id =1'') > > Here, result is actually an array of 1 item. > > The ''size'' method is a method of the Array class in ruby, and will only > work when the Model.find call returns an array. > > So, as in your example again: > > result = Stuff.find(1) > > Here, result is simply an instance of the ''Stuff'' class (i.e. the record > with id=1). Therefore the ''size'' method will not work because it is not > a method of the ''Stuff'' class. > > Hope that helps. > > ~ Mark > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---