Comments (2)
Your issue seems to be two parts;
Filtering for empty string
I think (regardless of the implementation), a user may assume that leaving a blank field (empty string) would not filter on that field at all; i.e. if you leave "age" blank, you would not filter by "age" at all.
I use the keyword BLANK
to indicate an explicit search for ""
on a given field. My filter config therefore looks like this;
def param_age(age_query)
return @results.where(age: nil) if age_query == 'BLANK'
@results.where(age: age_query)
end
Filtering with two fields at once
This can be achieved by deferring the logic to only one of the methods, although it's a little ugly.
def param_age(age_filter)
return @results.none if params[:rank].blank?
@results.where(age: age_filter, rank: params[:rank])
end
def param_rank(_)
# ignored here as rank cannot be filtered in isolation; see param_age.
end
Hope that helps with your use-case, at least?
from filterer.
Cool. I forgot about this! I'm no longer working on the project that needed this, and I'm not sure what I did. Cheers, and happy new year!
And yes, it does sound like what you put will solve it!
from filterer.
Related Issues (17)
- Baked in limit / offset? HOT 4
- Allow overriding the starting_query HOT 1
- Update badges to shields.io
- ability to assign default params HOT 1
- add method to ActiveRecord::Association? HOT 2
- Add some kind of performance benchmark HOT 1
- don't modify the params hash
- use kaminari/will_paginate HOT 10
- inherit from ActiveModel for form_for compat? HOT 1
- Using filterer without pagination HOT 2
- Add option for removing "limit" altogether HOT 1
- per_page causing error where string is compared to fixnum HOT 1
- Allow returning `nil` from param_* method HOT 1
- Rails 5 - to_hash is deprecated HOT 1
- Usage of "chain" and "filter" in Ruby 2.6 HOT 2
- undefined method `filter_without_pagination' for #<ActiveRecord::AssociationRelation []>
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from filterer.