ActiveStorage Callbacks

67 views
Skip to first unread message

Tom Rossi

unread,
May 20, 2019, 3:57:36 PM5/20/19
to rubyonra...@googlegroups.com
I'm not sure how common this is, but wondering if its worth working on a PR for ActiveStorage to allow you to use callbacks. Something like this for example to run a method after analyze is complete:

has_one_attached :artwork, after_analyze: :my_method

Ben Walsh

unread,
May 27, 2019, 10:20:44 AM5/27/19
to Ruby on Rails: Core
I had a similar need -- in my case I want to insert a cover letter at page 1 of a PDF attachment -- and I came up with this:


In the model, then:

include ActiveStorageCallbacks

perform_attach welcome_pack
: { before: :insert_cover_letter }


 
I tried a more sophisticated approach that injected the custom callback into the callback chain but it was hard so I gave up.
Reply all
Reply to author
Forward
0 new messages