Neil Middleton
Neil Middleton

Reputation: 22240

Raising an ActiveRecord error on RecordNotFound

Is there a way of doing a find_by_x that raises an exception if the record is not found?

Upvotes: 1

Views: 1285

Answers (1)

amitkaz
amitkaz

Reputation: 2712

added "!" at the end:

User.find_by_name "a" => return nil

User.find_by_name! "a" => raise error

Upvotes: 6

Related Questions