New topic Closed topic
avatar image
1
Can I prevent saving with a before_save action? Or in any way else?
By Created , last editted

Hi y'all,

I've got a rental_period model which has a start_datetime and an end_datetime. When a user saves a new rental_period I want to check if the two dates are valid (both cannot be in the past and the enddate must be greather than the startdate).


I've created an action with before save as the trigger, resulting in an error if these validations haven't been met. Now, the action triggers good and generates the error if the validations aren't met, but the record will still be saved. 


Can I somehow prevent the record from saving when the before_save results in an error?


Hi y'all,

I've got a rental_period model which has a start_datetime and an end_datetime. When a user saves a new rental_period I want to check if the two dates are valid (both cannot be in the past and the enddate must be greather than the startdate).


I've created an action with before save as the trigger, resulting in an error if these validations haven't been met. Now, the action triggers good and generates the error if the validations aren't met, but the record will still be saved. 


Can I somehow prevent the record from saving when the before_save results in an error?

Answers
Sort by:

This topic is closed.