adding items belongs_to relationship to Active Admin

孤者浪人 提交于 2019-12-04 02:11:38

问题


I'm using active admin for my rails app. 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.

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.

The delivery_time is showing up as -

#<DeliveryTime:0x00000107984268>

How do I show the date property of the delivery time model?


回答1:


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



来源:https://stackoverflow.com/questions/8819211/adding-items-belongs-to-relationship-to-active-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!