I have a Post model, PostSource model. A PostSource has many posts, a post belong to one PostSource.
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] }
with the controller as:
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.