Possible Duplicate:
Model.find(1) gives ActiveRecord error when id 1 does not exist
If there is no user with an id of 1 in the database, trying User.find(1) will raise an exception.
Why is this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because that’s the way the architects intended find(id) to work, as indicated in the RDoc:
If you don’t want the exception to be raised, use find_by_id, which will return nil if it can’t find an object with the specified id. Your example would then be
User.find_by_id(1).