简体   繁体   中英

Rails - ActiveAdmin - Filter another model

I use rails 4.2.4, and activeadmin gem.

I have 2 models.

User model: email:string, password: string .

User model has_one User Detail.

UserDetail is belongs_to User, it have name:string .

But, I filter name in

ActiveAdmin.register User do
  filter :name
end

I don't see name field.

Thanks.

You have to use the appropriate filter for the associated model. You can do this like:

ActiveAdmin.register User do
  filter :user_detail_name
end

Where name is an attribute of UserDetail model.


Update: Forgot to mention that ActiveAdmin utilizes ransack for search under the hood. Based on that you can use ransack 's syntax to setup your filters. Here are a couple of resources that could prove to be helpful:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM