laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org
2008-Feb-05 18:28 UTC
NoMethodError even though the method is there
Hi, I''m sure this will be an easy one, I''m just not seeing something really obvious. In my app/controllers/sessions_controller.rb file, I have this method: def create if (log_user_in(params[:login], params[:password], params[:remember_me])) user = User.find(session[:user_id]) if (user.is_subscriber?) # line 11 flash[:notice] = "Logged in successfully" redirect_to :controller => ''admin'' else flash[:notice] = "Logged in successfully" redirect_to :controller => ''order'', :action => ''new'' end else flash[:notice] = "Authentication failed." render :controller => ''register'', :action => ''start'' end end and in my User model, I have this method: class User < ActiveRecord::Base ... def self.is_subscriber? user_type_id == 1 end ... end but I''m getting this error: NoMethodError in SessionsController#create undefined method `is_subscriber?'' for #<User:0xb795d668> RAILS_ROOT: /usr/local/apache2/htdocs/easyrx Application Trace | Framework Trace | Full Trace /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ attribute_methods.rb:200:in `method_missing'' app/controllers/sessions_controller.rb:11:in `create'' What obvious thing am I missing? Thanks, - Dave --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Dave, I think your problem is that you have "def self.is_subscriber?" instead of "def is_subscriber?", which makes it a class method instead of an instance method. Try taking out the "self." part. Liam laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org wrote:> Hi, > > I''m sure this will be an easy one, I''m just not seeing something > really obvious. > .... > in my User model, I have this method: > > class User < ActiveRecord::Base > ... > def self.is_subscriber? > user_type_id == 1 > end > ... > end > > but I''m getting this error: > > NoMethodError in SessionsController#create > undefined method `is_subscriber?'' for #<User:0xb795d668> > RAILS_ROOT: /usr/local/apache2/htdocs/easyrx > Application Trace | Framework Trace | Full Trace > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > attribute_methods.rb:200:in `method_missing'' > app/controllers/sessions_controller.rb:11:in `create'' > > > What obvious thing am I missing? > > Thanks, - Dave-- 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 -~----------~----~----~----~------~----~------~--~---
def ... end in not with in the clas Xyz end.... On Feb 6, 2008 12:53 AM, Liam Morley <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hey Dave, I think your problem is that you have "def > self.is_subscriber?" instead of "def is_subscriber?", which makes it a > class method instead of an instance method. Try taking out the "self." > part. > > Liam > > > laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org wrote: > > Hi, > > > > I''m sure this will be an easy one, I''m just not seeing something > > really obvious. > > .... > > in my User model, I have this method: > > > > class User < ActiveRecord::Base > > ... > > def self.is_subscriber? > > user_type_id == 1 > > end > > ... > > end > > > > but I''m getting this error: > > > > NoMethodError in SessionsController#create > > undefined method `is_subscriber?'' for #<User:0xb795d668> > > RAILS_ROOT: /usr/local/apache2/htdocs/easyrx > > Application Trace | Framework Trace | Full Trace > > /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > > attribute_methods.rb:200:in `method_missing'' > > app/controllers/sessions_controller.rb:11:in `create'' > > > > > > What obvious thing am I missing? > > > > Thanks, - Dave > -- > Posted via http://www.ruby-forum.com/. > > > >-- Thanks & Regards, Pavan Agrawal NOTICE : This transmission contains information that may be confidential and that may also be privileged. Unless you are the intended recipient of the message or authorized to receive it for the intended recipient, you may not copy, forward, or otherwise use it, or disclose it or its contents to anyone else. If you have received this transmission in error please notify us immediately and delete it from your system. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---