新的和编辑表单上的rails activeadmin下拉菜单 [英] rails activeadmin drop down menu on new and edit forms

查看:54
本文介绍了新的和编辑表单上的rails activeadmin下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个has_many Emirates_to关联。我注册了资源。我有属于客户的货件。

I have a has_many belongs_to association. I registered the resource. I have shipments that belong to customers.

但是当我转到新的货件表格时,在下拉菜单中,客户编号为#< 0X0000>

But when I go to the new shipment form, in the drop down select menu for customers I get #<0X0000>

为什么?我该如何解决?

Why? How can I fix it?

我认为这是因为客户表没有名称属性,而我拥有company_name。如何在下拉菜单中使用company_name?

I think it's because the Customers table doesn't have a "name" attribute, instead I have company_name. How can I use company_name in the drop down menu?

推荐答案

不应覆盖 to_s方法,活动管理员可以在这种情况下专门使用display_name方法

You shouldn't override to_s method, active admin can use display_name method specially for this case

因此您可以在模型旁边添加

so you can add next to your model

  def display_name
    company_name
  end

这篇关于新的和编辑表单上的rails activeadmin下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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