Ryan P. wrote:
I have two form fields (select dropdowns) that are ‘startlocation’ and
‘endlocation’. These two cannot be equal to each other on save and I am
wondering how to put validation into the model for this. Is is possible
do it in the model, or do I need to do this in the controller?
Thanks in advance!
You can do it by overriding the validate method on the model e.g.
errors.add(‘startlocation’, ‘must be different to endlocation’) if
startlocation == endlocation
which will get called on every save. You can also override
validate_on_create and validate_on_update to get finer grained control.