I have a model that looks like this –
class Car < ActiveRecord::Base
validates :name,:presence =>true
end
Can I set it up so that the car’s name is not required when preforming a create action but it is required when doing an ‘edit’ action?
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.
Yup, that’s possible:
Might have a look at the Active Record Validations and Callbacks Guide.