David Karasek
David Karasek

Reputation: 348

find_by NoMethodError in Rails

I have the following line of code,

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

That is throwing an error

NoMethodError in SessionsController#create

undefined method `find_by' for #<Class:0x007f67187ef730>

Rails.root: /home/dj/portfolio/sample_app
Application Trace | Framework Trace | Full Trace

app/controllers/sessions_controller.rb:7:in `create'

In other parts of the code I have successfully used find_by_email with no error. What could be causing this method to not work?

Upvotes: 1

Views: 1188

Answers (1)

iblue
iblue

Reputation: 30404

You can either use User.find(email: "[email protected]") or User.find_by_email("[email protected]"). User.find_by does not exist.

Upvotes: 6

Related Questions