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?
To edit the validation rule for a custom activity field, select the validation rule from Setup by entering Activities in the Quick Find box, then selecting Activities and choose Task Validation Rules or Event Validation Rules. Enter the properties of your validation rule.
Never, ever, ever create validation rules directly in the Production environment. Run rules so narrowly as possible. Remember to notify users when there are new rules. Be careful not to create too many rules.
The detail page of a custom activity field doesn't list associated validation rules. Workflow rules and some processes can invalidate previously valid fields. Invalidation occurs because updates to records based on workflow rules and also on process scheduled actions don't trigger validation rules.
Yup, that's possible:
class Car < ActiveRecord::Base
validates :name, presence: true, on: :update
end
Might have a look at the Active Record Validations and Callbacks Guide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With