Skip to content

Rails 6 and 7 break kt-paperclip due to lack of :on support in callbacks #126

@wedgemartin

Description

@wedgemartin

Describe the bug
In Rails 6 and above, kt-paperlcip fails on line 98 in lib/paperclip/has_attached_file.rb where an :on condition is used for after_commit / destroy


 93     def add_active_record_callbacks
 94       name = @name
 95       @klass.send(:after_save) { send(name).send(:save) }
 96       @klass.send(:before_destroy) { send(name).send(:queue_all_for_delete) }
 97       if @klass.respond_to?(:after_commit)
 98         @klass.send(:after_commit, on: :destroy) do
 99           send(name).send(:flush_deletes)
100         end
101       else
102         @klass.send(:after_destroy) { send(name).send(:flush_deletes) }
103       end
104     end

To Reproduce
Steps to reproduce the behavior:

  1. Implement has_attached_file with any settings
  2. Attempt an rspec run, rails console, or start a puma server etc.
  3. Error will get thrown to the console
ArgumentError:
  Unknown key: :on. Valid keys are: :if, :unless, :prepend

Expected behavior
Should function normally.

Desktop (please complete the following information):

  • Amazon Linux2 and macos
  • All versions

Looks like someone else has hit this:
https://stackoverflow.com/questions/76966547/rails-7-argumenterror-unknown-key-on-valid-keys-are-if-unless-prepend

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions