0

Some had posted similar question as mine. I tried the solution to most of them. Some say ActiveAdmin is using Metasearch and some say it's using ransack. I tried both methods. My activeadmin version is 1.0.0.pre4 and rails 4.2.6 Follwing is my code for the user based filter:

ActiveAdmin.register Equipment do
    filter :user
end 

This gives me a user dropdown where I can select one of the user and it filters the result based on that user. Right now I have only 3 users so its fine. But in future it will grow to thousands. So instead I would like to have a contains field, where I can enter user name and filter. I tried changing to following:

filter :user, as: :string, label: 'User' 

and also

filter :items_user, as: :string

Didn't work. Can somebody please tell me what am I missing?

user3576036
  • 1,335
  • 2
  • 23
  • 51

1 Answers1

1

Try this,

filter :user_name, as: :string

where name is attribute of User Model.

Hardik Upadhyay
  • 2,639
  • 1
  • 19
  • 34
  • For some reason, `as: :string` does not work well on associations. On my case, it raises a `NoMethodError, undefined method 'user_name_contains' for Ransack::Search class: User, base: Grouping combinator: and Ransack::Search` – Kaka Ruto Aug 28 '18 at 21:47
  • how to filter for user's first name & last name – Pavan Kumar V Jan 19 '23 at 07:43
  • @pavankumarv you need to setup custom filter please refer https://stackoverflow.com/q/7983654/6270554 – Hardik Upadhyay Jan 20 '23 at 09:19