Question

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

Was it helpful?

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
scroll top