Can/should I customize an ActiveAdmin update action, or use a model callback instead?

StackOverflow https://stackoverflow.com/questions/22949105

  •  30-06-2023
  •  | 
  •  

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?

Était-ce utile?

La 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

Autres conseils

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!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top