No method defined in controller

47 views
Skip to first unread message

Rahul Arora

unread,
Apr 11, 2015, 3:23:13 PM4/11/15
to rubyonra...@googlegroups.com
Hello all,

i am working on login module of application i have the method defined in Model and calling it from controller but the error says no method defined in controller below are model and controller code
 class AuthenticationController < ApplicationController
def sign_in
    @user = User.new
    end

  def login
 
    username_or_email = params[:user][:username]
    password = params[:user][:password]

    if username_or_email.rindex('@')
      email=username_or_email
      user = User.authenticate_by_email(email, password)
    else
      username=username_or_email
      user = User.authenticate_by_username(username, password)
    end

    if user
      flash[:notice] = 'Welcome.'
      redirect_to :root
    else
       flash.now[:error] = 'Unknown user. Please check your username and password.'
       render :action => "sign_in"
    end

  end
end
For model
def self.authenticate_by_email(email, password)
  user = find_by_email(email)
  if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
    user
  else
    nil
  end
end
# Autentication by username
def self.authenticate_by_username(username, password)
  user = find_by_username(username)
  if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
    user
  else
    nil
  end
end

Kindly help ASAP

Colin Law

unread,
Apr 11, 2015, 4:32:05 PM4/11/15
to rubyonra...@googlegroups.com
On 11 April 2015 at 18:01, Rahul Arora <arorara...@gmail.com> wrote:
> Hello all,
>
> i am working on login module of application i have the method defined in
> Model and calling it from controller but the error says no method defined in
> controller below are model and controller code

Please copy/paste the full error message here, and tell us which line
of code it refers to.
We are not telepathic. At least I am not.

Colin
Reply all
Reply to author
Forward
0 new messages