Is there any way to initialize a model object like:
@review = current_user.reviews.build(params[:review])
and then check it’s validity against the validation rules in review.rb?
…without attempting to save the model object to the DB??
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.
You can use
@review.valid?to check if the model is valid without saving it to the database.PS: In fact you can add validations to any class without having to use database functionality by using
ActiveModel::Validations. See Railscast #219 for an example.