ActiveAdmin: sort by child association's property

前端 未结 4 1423
太阳男子
太阳男子 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:34

    That should also do the work:

    index do
      column City.model_name.human, :city, :sortable => 'cities.name'
    end
    
    controller do
      def scoped_collection
        end_of_association_chain.includes(:city)
      end
    end
    

提交回复
热议问题