How to custom ActiveAdmin using find_by request instead of ID for all actions

If you followed this railscast: http://railscasts.com/episodes/63-model-name-in-url-revised and have custom routes, you can fix the active_admin routes by placing this in the app/admin/user.rb:

before_filter :only => [:show, :edit, :update, :destroy] do
  @user = User.find_by_slug!(params[:id])
end

It's really close to the one shown by afiah, just slightly different.


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