adding items belongs_to relationship to Active Admin
-
27-10-2019 - |
سؤال
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?
المحلول
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