简体   繁体   English

向Active Admin添加项目归属关系

[英]adding items belongs_to relationship to Active Admin

I'm using active admin for my rails app. 我正在为我的Rails应用程序使用活动管理员。 I have a customer model which belongs_to a department and also belongs_to a delivery_time. 我有一个客户模型,它属于一个部门,也属于一个交付时间。

In my admin folder I have a customer.rb file for active admin. 在我的admin文件夹中,有一个现用admin的customer.rb文件。

That file looks like this - 该文件看起来像这样-

ActiveAdmin.register Customer
  index do |customer|
      column :department, :sortable => false
      column :delivery_time, :sortable => false
  end
end

Essentially, I'm trying to customise the customer section of active admin to show the name of department they belong to and what delivery time they belong to. 本质上,我试图自定义活动管理员的客户部分,以显示其所属部门的名称以及它们所属的交货时间。

The department model has a name and a some other properties - the name of the department is showing in my active admin screen - all works as expected. 部门模型具有一个名称和一些其他属性-部门的名称显示在我的活动管理屏幕中-均按预期工作。 The delivery_time model two properties has a date, which is of type date and availabilty - which is a boolean. delivery_time模型的两个属性都有一个日期,该日期的类型为date和availabilty-这是一个布尔值。

The delivery_time is showing up as - delivery_time显示为-

#<DeliveryTime:0x00000107984268>

How do I show the date property of the delivery time model? 如何显示交货时间模型的date属性?

The columns in the index can be customized this way: 可以通过以下方式自定义索引中的列:

  index do |customer|
      column :department, :sortable => false
      column "Delivery time", :sortable => false do |cust|
          cust.delivery_time.strftime("%X")
      end
  end

See the ActiveAdmin doc for reference 请参阅ActiveAdmin文档以获取参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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