I''m getting the error that exists? is an undefined method when I try and use it in a model. Basically, it''s something like this: if exists? :user_id => current_user.id From what I understand, exists? is in ActiveRecord::Base so a model should be able to use it, right? I''ve used find() successfully, so why not exists? It works if I do User.exists?, but not if I do just exists? which is odd...anyone have an answer to this? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 10 Nov 2008, at 10:20, Mike C wrote:> > I''m getting the error that exists? is an undefined method when I try > and use it in a model. Basically, it''s something like this: > > if exists? :user_id => current_user.id > > From what I understand, exists? is in ActiveRecord::Base so a model > should be able to use it, right? I''ve used find() successfully, so why > not exists? It works if I do User.exists?, but not if I do just > exists? which is odd...anyone have an answer to this?It''s a class method not an instance method. Fred> > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
So what''s the proper way to use it? self.exists? doesn''t work either...can I only do User.exists?? On Nov 10, 2:31 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 10 Nov 2008, at 10:20, Mike C wrote: > > > > > I''m getting the error that exists? is an undefined method when I try > > and use it in a model. Basically, it''s something like this: > > > if exists? :user_id => current_user.id > > > From what I understand, exists? is in ActiveRecord::Base so a model > > should be able to use it, right? I''ve used find() successfully, so why > > not exists? It works if I do User.exists?, but not if I do just > > exists? which is odd...anyone have an answer to this? > > It''s a class method not an instance method. > > Fred > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 10 Nov 2008, at 17:16, Mike C wrote:> > So what''s the proper way to use it? self.exists? doesn''t work > either...can I only do User.exists??Yum. That''s what it means for a method to be a class method: you call it on a class not an instance of the class. Fred> > > On Nov 10, 2:31 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 10 Nov 2008, at 10:20, Mike C wrote: >> >> >> >>> I''m getting the error that exists? is an undefined method when I try >>> and use it in a model. Basically, it''s something like this: >> >>> if exists? :user_id => current_user.id >> >>> From what I understand, exists? is in ActiveRecord::Base so a model >>> should be able to use it, right? I''ve used find() successfully, so >>> why >>> not exists? It works if I do User.exists?, but not if I do just >>> exists? which is odd...anyone have an answer to this? >> >> It''s a class method not an instance method. >> >> Fred >> >> > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---