Raising an ActiveRecord error on RecordNotFound
-
05-07-2019 - |
Question
Is there a way of doing a find_by_x that raises an exception if the record is not found?
Solution
added "!" at the end:
User.find_by_name "a" => return nil
User.find_by_name! "a" => raise error
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow