Rails 3 ActiveAdmin。如何设置关联记录的默认排序顺序? [英] Rails 3 ActiveAdmin. How to set a default sort order for an associated record?

查看:61
本文介绍了Rails 3 ActiveAdmin。如何设置关联记录的默认排序顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个发货模型和一个发票模型。发票属于装运。



所以我为装运添加了默认的排序顺序...

  config.sort_order ='file_number_desc'

但是现在我想为发票添加相同的排序顺序(装运表是具有file_number列的排序顺序),但这似乎不起作用:

  config.sort_order ='shipments.file_number_desc'


解决方案

很好的解决方案@Siwei,我只使用 scope:joined 而不是 scope:joined ,它默认情况下在名为Joined的列表顶部显示一个过滤器,如下所示:

 控制器执行
def scoped_collection
GenericItem.includes(:vendor)
结束
结束

将ActiveAdmin控制器修改为默认使用该范围,而不向用户显示。

I have a shipments model and an invoice model. The invoice belongs to shipment.

So I added a default sort order for shipment like this...

config.sort_order = 'file_number_desc'

But now I want to add the same sort order for invoices, (shipments table is the one that has the file_number column) but this doesn't seem to work:

config.sort_order = 'shipments.file_number_desc'

解决方案

Nice solution @Siwei, I would just use, instead of the scope :joined which by default shows a filter on top of the list called Joined, the following:

controller do
  def scoped_collection
    GenericItem.includes(:vendor)
  end
end

Which modifies the ActiveAdmin controller to use that scope as default, without showing it to the user.

这篇关于Rails 3 ActiveAdmin。如何设置关联记录的默认排序顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆