Rails 默认使用 MetaSearch 排序
我正在使用 gem 元搜索来提供一些排序功能。该页面默认为 created_at ASC
类型,但我希望它是 created_at DESC
,但我无法明确说明这一点,因为它将覆盖 MetaSearch 的排序功能。
def index
@search = Photo.search(params[:search])
end
关于如何实现这一目标有什么想法吗?
I am using the gem metasearch to provide some sorting features. The page is defaulting to a sort of created_at ASC
, but I want it to be created_at DESC
, but I can't explicitly state that because it will override MetaSearch's sort features.
def index
@search = Photo.search(params[:search])
end
Any thoughts on how to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题,最终在控制器中这样做,
默认排序顺序是在 DESC 处创建的,但如果在参数中收到新的排序顺序,它将被覆盖。似乎对我有用。
I had the same problem and ended up doing like this in the controller
Default sort order is created_at DESC, but it will be overwritten if a new sort order is received in the params. Seems to work for me.
尝试这种方法。它对我有用:
Try this approach. It works for me:
@search = Photo.search(params[:search])
@search.meta_sort = 'your_column.desc'
@search = Photo.search(params[:search])
@search.meta_sort = 'your_column.desc'