NoMethodError even though the method is there


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],
      user = User.find(session[:user_id])
      if (user.is_subscriber?) # line
        flash[:notice] = "Logged in successfully"
        redirect_to :controller => 'admin'
        flash[:notice] = "Logged in successfully"
        redirect_to :controller => 'order', :action => 'new'
      flash[:notice] = "Authentication failed."
      render :controller => 'register', :action => 'start'

and in my User model, I have this method:

class User < ActiveRecord::Base
  def self.is_subscriber?
    user_type_id == 1

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
attribute_methods.rb:200:in `method_missing'
app/controllers/sessions_controller.rb:11:in `create'

What obvious thing am I missing?

Thanks, - Dave

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."

Liam wrote:

def … end in not with in the clas Xyz end…