使用 Rails 3.1 应用程序更改活动管理中下拉关联过滤器中显示的属性
我在 Rails 应用程序中使用 Active Admin gem,并且在我的一个模型管理页面上,有一个用于与另一个模型关联的过滤器。下拉菜单显示 #
而不是相应的属性。
例如,如果我的模型是属于用户的帖子,那么在帖子管理索引页面上,将会有一个用户过滤器,并且在该过滤器的下拉菜单中将是 id,例如 #
。我希望能够在该过滤器的下拉菜单中显示适当的内容。如何使用 Active Admin 执行此操作?
更新
正如 ciastek 在答案中指出的,这与 这个问题事实上,我也使用“company_name”作为属性而不是“name”
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.
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
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能够通过传递
: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 activeadmin下拉菜单,回答相同。
Simmilar to rails activeadmin drop down menu on new and edit forms, answer the same.