Rails Active Admin how to config.sort_order with 2 columns (1 column from association)

别来无恙 提交于 2019-12-10 17:37:13

问题


In Active Admin would like to know how to setup config.sort_order with 2 columns where first column is come from same model and second column is from associated model?

ActiveAdmin.register Race do
  menu parent: :races, :label => proc{ I18n.t('activerecord.models.races') }
  belongs_to :meeting, :optional => true
  #need to order by "meetings.date desc races.time desc"
  config.sort_order = "?"



  controller do
    def scoped_collection
      end_of_association_chain.includes(:meeting)
    end
  end

end

回答1:


config.sort_order will accept sorting by multiple fields, the format is "field1_(asc|desc), field2_(asc|desc)" preserved backwards compatibility.

Please check this link for reference. https://github.com/activeadmin/activeadmin/pull/2432. It may resolve your problem.



来源:https://stackoverflow.com/questions/18212983/rails-active-admin-how-to-config-sort-order-with-2-columns-1-column-from-associ

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