# what is .....undefined method \`authenticate'

**URL:** <https://discuss.rubyonrails.org/t/what-is-undefined-method-authenticate/28790>\
**Category:** rubyonrails-talk\
**Created:** [April 30, 2008, 7:25pm UTC](https://discuss.rubyonrails.org/t/what-is-undefined-method-authenticate/28790 "2008-04-30T19:25:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 30, 2008, 7:25pm UTC](https://discuss.rubyonrails.org/t/what-is-undefined-method-authenticate/28790/1 "2008-04-30T19:25:56Z")

</div>

def login\_submit &nbsp;&nbsp;&nbsp;if session['user'] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@logged\_in = true &nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@logged\_in = false &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@user = User.new(params['user']) &nbsp;&nbsp;&nbsp;&nbsp;if session['user'] = User.authenticate(params['user']['username'], params['user']['password']) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash[:notice] = l(:user\_login\_succeeded) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirect\_to :action =\> 'list' &nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@login = params['user']['login'] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash.now[:notice] = l(:user\_login\_failed) &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end

---

<div class="post-metadata">

**Author:** ![Roger\_Pack](https://avatars.discourse-cdn.com/v4/letter/r/50afbb/32.png) [@Roger\_Pack](https://discuss.rubyonrails.org/u/Roger_Pack)\
**Post date:** [April 30, 2008, 9:57pm UTC](https://discuss.rubyonrails.org/t/what-is-undefined-method-authenticate/28790/2 "2008-04-30T21:57:16Z")

</div>

do you have a user model with that method defined?

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [May 1, 2008, 4:09am UTC](https://discuss.rubyonrails.org/t/what-is-undefined-method-authenticate/28790/3 "2008-05-01T04:09:02Z")

</div>

HERE IS MY USER CONTROLLER---------

class UserController \< ApplicationController

&nbsp;&nbsp;layout "home"

&nbsp;&nbsp;def list &nbsp;&nbsp;&nbsp;&nbsp;@user = User.find(:all) &nbsp;&nbsp;end

&nbsp;&nbsp;def new &nbsp;&nbsp;&nbsp;&nbsp;@user = User.new &nbsp;&nbsp;end

&nbsp;&nbsp;def create &nbsp;&nbsp;&nbsp;&nbsp;@user = User.new(params[:user]) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if @user.save &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirect\_to :action =\> 'list' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirect\_to :action =\> 'new' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;def login &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@user = User.new &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@user.username = params[:user][:username] &nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;def login\_submit &nbsp;&nbsp;&nbsp;username = params[:user][:username] &nbsp;&nbsp;&nbsp;&nbsp;password = params[:user][:password] &nbsp;&nbsp;&nbsp;&nbsp;if session["user"] = User.authorize(username, password) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@user = User.find(session["user"].id) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@user.first\_login = 1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@user.save &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash[:notice] = "You are now logged in" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirect\_to :action =\> 'create' &nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash[:error] = "Incorrect username and/or password" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirect\_to :action =\> 'list' &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end end

---

<div class="post-metadata">

**Author:** ![Prasad](https://avatars.discourse-cdn.com/v4/letter/p/9de0a6/32.png) [@Prasad](https://discuss.rubyonrails.org/u/Prasad)\
**Post date:** [May 1, 2008, 6:37am UTC](https://discuss.rubyonrails.org/t/what-is-undefined-method-authenticate/28790/4 "2008-05-01T06:37:41Z")

</div>

You should have a method authenticate defined in User model.

In your case, authenticate method must be defined in User model as

class User \< ActiveRecord::Base &nbsp;&nbsp;validates\_presence\_of :username, :message=\>"User Name will not bblank" &nbsp;&nbsp;validates\_presence\_of :password, :message=\>"Password cannot be blank"

# # # # Authenticate method # # # &nbsp;&nbsp;def self.authenticate(login, pass) &nbsp;&nbsp;&nbsp;&nbsp;find(:first, :conditions=\>["login = ? AND password = ?", login, pass]) # login, password are your users table fields.. &nbsp;&nbsp;end

end

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [May 1, 2008, 6:10pm UTC](https://discuss.rubyonrails.org/t/what-is-undefined-method-authenticate/28790/5 "2008-05-01T18:10:10Z")

</div>

Thx prasad...........

my prog is running successfully........

in future also if i have any problem i wil contact u........ can u give me u r email-id....

Thnx a lot....... 🙂
