How to customize edit and update action in rails_admin
Asked Answered
D

3

10

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?

Davis answered 21/11, 2012 at 22:4 Comment(2)
I'm pretty sure you can't right now override the standard actions - you can however create custom actions as exhibited here github.com/sferik/rails_admin/wiki/ActionsUnobtrusive
Hey, did you find any way of implementing thisCrenate
C
0

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
Chiarra answered 22/12, 2013 at 0:36 Comment(0)
C
0

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.

Crenate answered 26/1, 2017 at 11:2 Comment(0)
B
0

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
Bustos answered 3/10, 2018 at 22:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.