1

I use:

def to_param
    user_name
end

and in my active admin user.rb

ActiveAdmin.register User do
  index do
      column :id
      column :email
      column :user_name
      column :created_at
      default_actions
  end
end

That of course gives me an Couldn't find User with id=testuser

How can i specify to Active Admin to use this properly ?

Edit 1: With the answer below it works but def to param get's overwritten on all the app..

Mini John
  • 7,855
  • 9
  • 59
  • 108

3 Answers3

2

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
Mini John
  • 7,855
  • 9
  • 59
  • 108
2

You want to override the default finder:

controller do
  defaults :finder => :find_by_user_name
end
Daniel Magliola
  • 30,898
  • 61
  • 164
  • 243
1

Override the to_param implementation for ActiveAdmin

ActiveAdmin.register Foobar do
  before_filter do
    Foobar.class_eval do
      def to_param
        id.to_s
      end
    end
  end
end

Refer to this SO post for more info/alternate solution related to this topic

Community
  • 1
  • 1
usha
  • 28,973
  • 5
  • 72
  • 93
  • 1
    Hey vimsha, although it works with Active Admin, INAPP all def to params are overwritten to :id and nothing works... Is there a viable Solution to this ? – Mini John Oct 17 '13 at 16:55