ActiveStorage Callbacks

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ActiveStorage Callbacks

Tom Rossi
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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/CAJAxyre8zFdeim0XHFFQ04qfNRnXABzQ_GvBoSbYqbC4pJeouQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: ActiveStorage Callbacks

Ben Walsh
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.




On Monday, 20 May 2019 20:57:36 UTC+1, Tom Rossi wrote:
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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/f42eba14-2be0-4c6c-bce5-319ed32043cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.