问题
Is there a way of doing a find_by_x that raises an exception if the record is not found?
回答1:
added "!" at the end:
User.find_by_name "a" => return nil
User.find_by_name! "a" => raise error
来源:https://stackoverflow.com/questions/1400467/raising-an-activerecord-error-on-recordnotfound