Question

I'm using rails_admin and I think it's great. Unfortunately I can't get to override a specific action on a specific model. I just need to override edit and update behavior on one model. Any idea?

No correct solution

OTHER TIPS

I dont know what you have tried in the past and it would be of great help if you post that but you can not try this

config.model 'Model' do
  edit do
    ....
  end

  update do
    ....
  end
end

Well, considering what you are trying to do. I believe you can achieve it using ROR callbacks too and this would be much easier.

So In your model file

after_update :custom_action

#define custom_action in the same model
def custom_action
  #your code goes here
end

You might have to check that this action is performed by the admin and that's it.

Sorry for being 4 years late. But this might help others.

You can add additional update behavior by tapping-in to the Auditing support.

In my case, I needed to log when certain fields were changed on a particular model, along with the user that made the change. I achieved that with:

RailsAdmin.config do |config|
  config.audit_with { @auditing_adapter = MyAuditor.new(self) }
end

class MyAuditor
  def update_object(object, _abstract_model, user, changes)
    if object.is_a?(SomeModel)
      changes = changes.slice(:important_field, :other_important_field)
      if changes.present?
        # ... log change ...
      end
    end
  end

  # other auditor methods (unused)
  def initialize(_controller) end
  def create_object(_object, _abstract_model, _user) end
  def delete_object(_object, _abstract_model, _user) end
  def latest() end
  def listing_for_object(*_args) end
  def listing_for_model(*_args) end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top