ActiveAdmin: sort by child association's property

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

    Very simple and readable solution:

    index do
      column :city, sortable: "cities.name"
    end
    
    controller do
      def scoped_collection
        # join cities
        super.includes :city
      end
    end
    

提交回复
热议问题