[英]Rails - ActiveAdmin - Filter another model
I use rails 4.2.4, and activeadmin gem. 我使用Rails 4.2.4和activeadmin gem。
I have 2 models. 我有2个模型。
User model: email:string, password: string
. User model: email:string, password: string
。
User model has_one
User Detail. 用户模型
has_one
用户详细信息。
UserDetail is belongs_to
User, it have name:string
. UserDetail是
belongs_to
用户,它具有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. 其中,
name
是UserDetail
模型的属性。
Update: Forgot to mention that ActiveAdmin
utilizes ransack
for search under the hood. 更新:忘了提,
ActiveAdmin
利用ransack
的引擎盖下的搜索。 Based on that you can use ransack
's syntax to setup your filters. 基于此,您可以使用
ransack
的语法来设置过滤器。 Here are a couple of resources that could prove to be helpful: 这里有一些资源可能会有所帮助:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.