Viren Negi
2011-Feb-07 09:42 UTC
Mixing a Array Object with ActiveRecord::Base Array Object
Hello, Most of You might find this very weird but I have no way out of it I have a method that return a Array Object the method goes like this in User Model def accessible_websites if self.is_super_admin? ## if Super Admin Display all Website Website.all elsif self.is_admin? ## if only Admin then display all websites only for the account for which he is admin. self.account.websites else ## display all the website for the account in the groups which he is been assigned to(i.e Normal User) self.account.websites.find(:all,:joins => [:group_websites => {:group => :users}],:conditions=>["users.id =?",self]).uniq end end the code is made generic in User Model to avoid code duplication else where Problem is If its a Normal User the below code return a "Array" whose superclass is "Object" and not "ActiveRecord::Base" Here what I meant current_user.accessible_website.class.superclass => Object so current_user.accessibe_website.find_by_id() ## return error or current_user.accessible_website.find_by_status("disable") ## return error rightly so coz it not an Array of ActiveRecord::Base Object Here what i meant if Someone do this Website.all.class.superclass => "ActiveRecord::Base" so the object is still suitable for any further SQL related task like "find_by_id" etc because the object return has a superclass "ActiveRecord" and not "Object" So .. Is there a way can I Mix the "ActiveRecord::Base" method in "Array" of superclass "Object" so that hence forth the object is suitable for any further SQL related task Regards Viren Negi -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Feb-07 11:47 UTC
Re: Mixing a Array Object with ActiveRecord::Base Array Object
On Feb 7, 9:42 am, Viren Negi <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> So .. > Is there a way can I Mix the "ActiveRecord::Base" method in "Array" of > superclass "Object" so that hence forth the object is suitable for any > further SQL related taskRather than calling find :all, see if you can use a named_scope (or just plain scope in rails 3) instead Fred> > Regards > Viren Negi > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.