ActiveAdmin: sort by child association's property

前端 未结 4 1421
太阳男子
太阳男子 2021-02-13 17:08

I am having these objects:

class District < ActiveRecord::Base
  belongs_to :city
end
class City < ActiveRecord::Base
  has_many :districts
end
         


        
4条回答
  •  盖世英雄少女心
    2021-02-13 17:13

    Try this.. It will help....

    index do
      column :city, :sortable => :"cities.name" do |district|
        district.city.human_name(:count => :other) if district.city.present?
      end
    end
    
    controller do
      def scoped_collection
        District.includes(:city)
      end
    end
    

提交回复
热议问题