user3074285
user3074285

Reputation: 1

NoMethodError in SessionsController#create (undefined method `find_by')

def create
  @user = User.find_by(email: params[:session][:email].downcase)
  if user && user.authenticate(params[:session][:password])
    sign_in user
    redirect_to user
  else
    flash[:error] = 'Invalid email/password combination'
    render 'new'
  end
end

By using above code, I am unable to sign in with my details. Hope, some one will help me out of this....

Thanks in Advance

Upvotes: 0

Views: 420

Answers (1)

Marek Lipka
Marek Lipka

Reputation: 51171

Change your first line in create method to:

@user = User.find_by_email(params[:session][:email].downcase)

The reason you get this error is that you probably use Rails 4 find_by method in Rails 3 application.

Upvotes: 2

Related Questions