如何在activeadmin rails的过滤器下拉列表中添加排序的元素 [英] how to add sorted elements in the filter dropdown in activeadmin rails

查看:68
本文介绍了如何在activeadmin rails的过滤器下拉列表中添加排序的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Post模型,PostSource模型。一个PostSource有很多帖子,一个帖子属于一个PostSource。

I have a Post model, PostSource model. A PostSource has many posts, a post belong to one PostSource.

使用ActiveAdmin,在Post的Index操作中,我以这种方式显示PostSource的过滤器: / p>

Using ActiveAdmin, in the Index action of the Post, I am displaying a filter of PostSource this way:

filter :post_source, label: 'Source'
filter :category, as: :select, collection: Category.order(:name).collect { |cat| [cat.name, cat.id] }

,控制器为:

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

它显示源,但不按排序顺序显示。在这种情况下如何对过滤器进行排序?

It displays the source, but does not display in a sorted order. How to sort the filter in this case?

我尝试在过滤器上添加可排序的订单,但似乎不起作用

I tried adding sortable, order on filter but it does not seem to work

推荐答案

如果您要对第一个过滤器( post_source)进行排序,则只需在第二行中添加一个集合,然后在一个块内进行排序即可。

If you're trying to sort the first filter ('post_source'), you could just add a collection as you have in your second line, and sort within a block.

filter :post_source, label: 'Source', collection: proc { PostSource.order(:name) }

第二个示例中也可以使用此语法。

This syntax might be used as an alternative in the second example as well.

这篇关于如何在activeadmin rails的过滤器下拉列表中添加排序的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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