【问题标题】:Rails Active Admin how to config.sort_order with 2 columns (1 column from association)Rails Active Admin 如何使用 2 列 config.sort_order(关联中的 1 列)
【发布时间】:2015-05-20 13:37:59
【问题描述】:

在 Active Admin 中想知道如何使用 2 列设置 config.sort_order,其中第一列来自同一模型,第二列来自关联模型?

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

【问题讨论】:

标签: ruby-on-rails sql-order-by activeadmin


【解决方案1】:

config.sort_order 将接受多个字段的排序, 格式为“field1_(asc|desc), field2_(asc|desc)” 向后保留 兼容性。

请查看此链接以供参考。 https://github.com/activeadmin/activeadmin/pull/2432。它可能会解决您的问题。

【讨论】:

  • 该 PR 从未合并。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多