Question

My Rails app has events and users. In ActiveAdmin, an event can be edited via the form action. If the edit includes attaching a user to the event, I need to send a message to that user. I think I need to either customize the update action or trigger the message-send in an :after_update callback in my event model.

I guess it makes more sense to add a callback, but I'm curious whether it's possible to customize the update action in ActiveAdmin. Is it?

Was it helpful?

Solution

You can edit ActiveAdmin controller actions, but if the action you do after update is the same when updating form outside admin panel than it's better to use callbacks I guess. Why writing more code?

http://activeadmin.info/docs/8-custom-actions.html#modify_the_controller

  ActiveAdmin.register Post do

    controller do
      # This code is evaluated within the controller class

      def define_a_method
        # Instance method
      end
    end

  end

OTHER TIPS

It's definitely possible, in your ActiveAdmin model just add :

controller do
def update_resource(object, attributes)
  attributes.first[:your_attribute] = ...
  object.send(:update_attributes, *attributes)
end

Hope it helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top