Rails Beginner.. NoMethodError

Dear all

I encounter error when I login my Web application
NoMethodError in AdminController#login
undefined method `get_title' for #<Class:0x63ac78>

Here is part of my code
  def login
    session[:user_id] = nil
    if request.post?
      if User.authenticate(params[:name], params[:password])
        user = User.find_by_name(params[:name])
        if !user
          user = User.new
          user.name = params[:name]
          user.title = User.get_title #I think this trigger the error
        session[:user_id] = params[:name]
        redirect_to(:controller => 'ecpath_app_version', :action =>
        #flash[:notice] = "Invalid user/password combination"

Here is my user model
require 'net/ldap'

class User < ActiveRecord::Base

  set_table_name "users"
  attr_accessor :title

  def self.authenticate(username,password)
    treebase = "dc=corp,dc=ha,dc=org,dc=hk"
    filter = Net::LDAP::Filter.eq( "sAMAccountName", username )
    login_succeeded = false
    ldap_con = initialize_ldap_con(username,password)
    if ldap_con.bind
      login_succeeded = true
      @title=ldap_con.search( :base => treebase, :filter => filter,
:attributes => 'displayname').first.displayname.to_s

  # I have define the get_title here..
  def get_title
    return @title

My users table schema
name varchar(20)
created_at datetime
updated_at dataetime
title varchar(30)

Please give me some advices. Thank you.


try changing User.get_title to user.get_title
you are trying to access a method on the class instead of on the instance.