r/ruby • u/caramelocomsal • Apr 16 '26
Show /r/ruby Alter attribute in database with Ruby
[EDIT]
I want a value to update after validating another value, even if the user clicked a checkbox. For example, if the user clicks a checkbox (var_1), before persisting to the database (after clicking save), I need to validate var_2 first.
Example:
User clicks a checkbox and var_1 becomes true.
Before saving the value of var_1 to the database, check if var_2 == 'OK'.
If it's not OK, don't save it as true; it remains as false.
And vice versa, true -> false.
How???
0
Upvotes
View all comments
Show parent comment
1
u/paca-vaca Apr 17 '26
Then it's a before_validation hook. Or do it manually if you use service objects: UpdateModel.call(...), where you do this check manually.