Want to have an Online Store but don't know where to start?
Click here and start selling online!

ActiveAdmin filter, from drop-down to textfield

February 2, 2012 | In: activeadmin, admin, gem, rails, ruby

ActiveAdmin is a wonderful rails gem(module) that’s really helpful for us developers because we don’t have to do such mundane task of creating an ‘admin’ panel for the site. You can see it’s full feature here .

All the built-in features are good enough, but i had this task that i need to change the default filter, from drop-down into textfield so the ‘admin’ can easily find the item he/she is looking for especially if the list has hundreds or even thousands of entries.

Here is the scenario:

I have a ‘Member’ model which ‘belongs_to’ a ‘Group’ which has many ‘members’, thus I have both ‘models/member.rb’ and ‘models/group.rb’ files.

All the built-in features are good enough, but i had this task that i need to change the default filter, from drop-down into textfield so the ‘admin’ can easily find the item he/she is looking for especially if the the drop-down list has hundreds or even thousands of entries.

class Member < ActiveRecord::Base
  belongs_to :group
  ## rest of the code here
end
 
class Group < ActiveRecord::Base
  has_many :members
  ## rest of the code here
end

ActiveAdmin auto-magically maps the association of these 2 models and its default filter element for Member is it has a drop-down list of all the Groups.

ActiveAdmin auto-magically maps the association of these 2 models and its default filter element for Member is it has a drop-down list of all the Groups.

  # this is the default, drop-down list of all groups
   filter :group

So to change this into a ‘textfield’:

  ActiveAdmin.register Member do
     filter :group_name, :as => :string
  ## rest of the code here
  end

Given that your ‘groups’ table has ‘name’ column, well you should because that’s part of the rails convention (to have name-field for every tables).

Share on Facebook


2 Responses to ActiveAdmin filter, from drop-down to textfield

Avatar

cahit

February 18th, 2012 at 4:35 am

can you pelsae guide me that how can I add the auto load functionality to my text filed , I have added to my custom form ? I am newbie pelsae guide me in detail. I will really appreciate your effort.

Avatar

zeratool

February 19th, 2012 at 8:33 pm

Hi Cahit,

Thanks for the comment, can you please explain more what you meant by “how can I add the auto load functionality to my text filed “?

Comment Form

Advertisement

Get Updates

Subscribe
free counters