avo icon indicating copy to clipboard operation
avo copied to clipboard

[Feature] Provide hooks in controller actions

Open bear-in-mind opened this issue 3 years ago • 5 comments
trafficstars

Feature

Provide hooks on create or update after save to perform some actions. Here's what I'm trying to achieve:

class Avo::EmailsController < Avo::ResourcesController
  def create
    super
    # This is not being called
    @model.send_as_reply
  end
end

Here's how it could work:

class Avo::EmailsController < Avo::ResourcesController
  def create
    super do |resource|
      resource.send_as_reply
    end
  end
end

Current workarounds

Right now, we can hook onto these actions through ActiveRecord callbacks, but it's not always convenient.

Additional context

A simple and good implementation is the pattern used in the devise controllers, where the resource is being yield if a block is passed : https://github.com/heartcombo/devise/blob/f8d1ea90bc328012f178b8a6616a89b73f2546a4/app/controllers/devise/registrations_controller.rb#L20

bear-in-mind avatar Jun 23 '22 08:06 bear-in-mind

It's probably 20 mn of work which I'd gladly take on this week if you find it interesting :)

bear-in-mind avatar Jun 23 '22 08:06 bear-in-mind

YES! I want that! That looks amazing!

I launched Avo on Product Hunt (any feedback and comments help a lot BTW) and my efforts go there today. But I'm happy to help more hands-on from tomorrow 💪

adrianthedev avatar Jun 23 '22 09:06 adrianthedev

Upvoted ✅ Congrats on the launch !

bear-in-mind avatar Jun 23 '22 11:06 bear-in-mind

This issue has been marked as stale because there was no activity for the past 15 days.

github-actions[bot] avatar Jul 14 '22 03:07 github-actions[bot]

We're going to use this approach.

adrianthedev avatar Aug 08 '22 19:08 adrianthedev