I have a model called book. I want to be able to check if it has a book with the id of some number. It’s a simple question, and I’m just learning. Don’t be too harsh….
Share
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.
Well, it’s simply:
It will render an object or nil.
Don’t use
Book.find(your_id), because it raises an exception if no book has the expected id.I strongly advise you to check http://railsforzombies.org to learn Rails.