Rollback record with Carbonite
I'm trying to achieve the title result.
The problem is that trying to set some fields (like foreign keys and timestamps) back to their previous values will mark the changeset as invalid.
I'm using
force_change_attributes
to try to overcome the problem but it is not woking.
Is there a way to force the changeset to accept all attributes changes without validating them?
Or is there a better way to achieve what I'm trying to achieve?
2 Replies
Hmm…well, you don’t generally want to use
Changeset.new
The documentation for that function explains it
And then I’d probably suggest:
Write an action that accepts all attributes and has arguments for all private/immutable attributes and uses something like change set_attribute(:updated_at, arg(:updated_at))
to force change them.So here is the solution: