I'm just adding ActiveAdmin to my app, I got a problem using show/edit/destroy action cause my link doesn't point to ID but to users name (in order to be more readable for user).
ActiveAdmin correctly create my link like:
edit link:
http://localhost:3000/admin/users/paul/edit (where paul is the user name)
in that case I get:
Couldn't find User with ID=paul
cause of course Paul is not the id but the user name.
How can I custom ActiveAdmin to use find_by_name(params[:id]) like in my application for all the action show/edit/delete?
In other model I got a so called "SID" which is a generated salted ID and I would like to use also the find_by_sid(params[:id]) as well for other models.
There is a cleaner way to do this:
ActiveAdmin.register User do
controller do
defaults :finder => :find_by_slug
end
end
This will do the job in the app/admin/user.rb :
ActiveAdmin.register User do
before_filter :only => [:show, :edit, :update, :destroy] do
@user = User.find_by_name(params[:id])
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With