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
controller/admin_controller.rb
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
user.save
end
session[:user_id] = params[:name]
redirect_to(:controller => ‘ecpath_app_version’, :action =>
‘index’)
else
#flash[:notice] = “Invalid user/password combination”
end
end
end

Here is my user model
model/user.rb
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
end
login_succeeded
end

I have define the get_title here…

def get_title
return @title
end

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

Please give me some advices. Thank you.

Valentino

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

Cheers
Simon

On Fri, 28 Nov 2008 13:28:23 +0900, Valentino L.