Reputation: 22240
Is there a way of doing a find_by_x that raises an exception if the record is not found?
Upvotes: 1
Views: 1285
Reputation: 2712
added "!" at the end:
User.find_by_name "a" => return nil
User.find_by_name! "a" => raise error
Upvotes: 6