I have dynamic form with conditional attributes.
E.g. if radio button "condition1" is checked, when "price" field hides dynamically via jQuery, and "percentage" field appears.
Let's say I created record with "condition1" radio box and set "percentage" value. Then, I decided to update record, and disabled "condition1", so percentage field hides, and I set new value for "price".
The problem is, that if I disable "condition1", "percentage" parameter is still present, and what I need is either "price" or "percentage" parameter at a time. I can removeAttribute() with jQuery on click, but this is bad user experience, because in some fields I have multiline textareas and I don't want to force users to write all again if they accidentally clicked on radio button.
I tried playing with ActiveModel::Dirty with no luck
in edit action of object's controller
if @object.condition_changed? && @object.condition_was == "condition1"
@object.attribute(:percentage, nil)
end
you can run a after update callback like