filterrific
filterrific copied to clipboard
Scope with arity 0 and enum requests compatible
Hello,
I really wanted to use my enum-styled queries and 0-parameters scope. I've adapted filterriffic in a way to afford that. As arity for scope and enums doesn't work as expected I use the ArgumentError exception.
filterrific_available_filters.each do |filter_name|
filter_param = filterrific_param_set.send(filter_name)
next if filter_param.blank? # skip blank filter_params
begin
ar_rel = ar_rel.send(filter_name, filter_param)
rescue ArgumentError #if we have a scope with arity 0 or enum query, we can perform the request without the parameter
ar_rel = ar_rel.send(filter_name) if (filter_param == 1)
end
end
ar_rel
end
There's still this issue with scope methods arity... https://github.com/activerecord-hackery/meta_search/issues/19 I think it would be better to use the scope arity in order to define the use of params. That would let checkboxes activate filter.
@jhund what's your mind about that?
Hi! Is there more work to be done to merge this one? Happy to help.