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?
Asked
Active
Viewed 2,994 times
10

leppie
- 115,091
- 17
- 196
- 297

user1170896
- 719
- 1
- 7
- 19
-
I'm pretty sure you can't right now override the standard actions - you can however create custom actions as exhibited here https://github.com/sferik/rails_admin/wiki/Actions – Chris O'Sullivan Jun 02 '15 at 10:43
-
Hey, did you find any way of implementing this – Hassan-Zahid Jan 25 '17 at 13:18
3 Answers
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

MZaragoza
- 10,108
- 9
- 71
- 116
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.

Hassan-Zahid
- 417
- 1
- 7
- 21
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

code_monkey_steve
- 191
- 4
- 4