使用Rails 3.1应用程序更改活动管理员的下拉关联过滤器中显示的属性 [英] Changing what attribute is displayed in drop down association filter in active admin with Rails 3.1 app

查看:57
本文介绍了使用Rails 3.1应用程序更改活动管理员的下拉关联过滤器中显示的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Rails应用程序中使用Active Admin gem,并且在我的一个模型管理页面上,有一个过滤器用于与另一个模型的关联。下拉菜单显示#< Model:AxAAAAAA> 而不是适当的属性。

I am using the Active Admin gem in my Rails app, and on one of my models admin page, there is a filter for an association to another model. The drop down menu is displaying #<Model:AxAAAAAA> as opposed to the appropriate attribute.

例如,如果我的模型是帖子管理索引页面上属于用户的帖子,则将为用户提供一个过滤器,并且在该过滤器的下拉菜单中为id,例如#<用户:abcd12345> 。我希望能够在此过滤器的下拉菜单中显示适当的内容。

For instance, if my model were posts, which belonged to users, on the posts admin index page, there would be a filter for users, and in the drop down menu for that filter would be id's such as #<User:abcd12345>. I would like to be able to display something appropriate in the drop down menu for this filter. How can I do this with Active Admin?

UPDATE

正如ciastek的回答所指出的那样,该如何使用Active Admin做到这一点?与此问题和事实上,我也使用 company_name作为属性,而不是 name

As pointed out in the answer by ciastek, this is very similar to this question and in fact, I am also using "company_name" as an attribute instead of "name"

推荐答案

我能够通过以下方式解决问题传递:label_method => :company_name 到 admin目录下resources.rb文件中的资源。

I was able to solve my problem by passing :label_method => :company_name to the resource in the resources.rb file under the 'admin' directory.

这篇关于使用Rails 3.1应用程序更改活动管理员的下拉关联过滤器中显示的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆