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

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

  •  30-06-2023
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top