[英]Fixed sort with Filterrific
I am implementing Filterrific in Rails 5, but do not require a sort function. 我正在Rails 5中实现Filterrific,但不需要排序功能。 Instead, I am trying to set a specific sort criteria that will not change, so no sort field on view, or option select. 相反,我尝试设置不会改变的特定排序标准,因此视图上没有排序字段,也没有选择选项。 I am struggling to get it to recognise the scope change that I have made. 我正在努力让它认识到我所做的范围更改。 Any help greatly appreciated... 任何帮助,不胜感激...
The error I get is generated by the controller: 我得到的错误是由控制器生成的:
"Invalid default filter params: ["sorted_by"]" “无效的默认过滤器参数:[“ sorted_by”]“
Model: 模型:
scope :sorted_by, lambda { |sort_option|
case sort_option
when /^date_desc/
order("account_xactions.xaction_date desc")
end
}
filterrific(
default_filter_params: { sorted_by: 'date_desc' },
available_filters: [
:search_query,
:with_account_id
]
)
Controller: 控制器:
@filterrific = initialize_filterrific(
AccountXaction,
params[:filterrific],
:select_options => {
with_account_id: Account.options_for_select
}
) or return
@account_xactions = @filterrific
What were you thinking Lloydo... 你在想劳埃多...
You forgot to add the scope into the available_filters section and furthermore, you didn't add the find method for the call to filterrific in the controller. 您忘记了将作用域添加到available_filters部分,此外,您没有在控制器中添加find方法来调用filterrific。
filterrific(
default_filter_params: { sorted_by: 'date_desc' },
available_filters: [
:sorted_by,
:search_query,
:with_account_id
]
)
Call in controller: 调用控制器:
@account_xactions = @filterrific.find
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.