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?
How to customize edit and update action in rails_admin
Asked Answered
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/Actions –
Unobtrusive
Hey, did you find any way of implementing this –
Crenate
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
© 2022 - 2024 — McMap. All rights reserved.