Skip to content

Commit

Permalink
Fix callback to only run before update
Browse files Browse the repository at this point in the history
`before_save` doesn't accept `:on` as an argument, so this callback was actually running on all save events, not just on update.

rails/rails#17622

Depending on what `reset_timestamp_attrs_for_update_if_needed` does, this might need to be backported to older versions.

I've submitted a PR to Rails to raise an exception when unexpected arguments are passed... unsure if an exception is the right way to go when there might be quite a few gems with this bug.

rails/rails#30919
  • Loading branch information
seanlinsley authored and aried3r committed Dec 14, 2020
1 parent 0ca066f commit 1a76e58
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/paper_trail/model_config.rb
Expand Up @@ -59,7 +59,7 @@ def on_destroy(recording_order = "before")

# Adds a callback that records a version after an "update" event.
def on_update
@model_class.before_save(on: :update) { |r|
@model_class.before_update { |r|
r.paper_trail.reset_timestamp_attrs_for_update_if_needed
}
@model_class.after_update { |r|
Expand Down

0 comments on commit 1a76e58

Please sign in to comment.