https://github.com/platbr/where_unless_blank
This gem removes statements with null/blank values from query.
https://github.com/platbr/where_unless_blank
activerecord activerecord-queries rails
Last synced: 2 months ago
JSON representation
This gem removes statements with null/blank values from query.
- Host: GitHub
- URL: https://github.com/platbr/where_unless_blank
- Owner: platbr
- License: gpl-3.0
- Created: 2019-09-27T14:01:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-30T11:44:35.000Z (over 6 years ago)
- Last Synced: 2025-12-06T14:52:56.569Z (6 months ago)
- Topics: activerecord, activerecord-queries, rails
- Language: Ruby
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WhereUnlessBlank
The behavior of "where" when querrying for a null value is include the statment and return rows with null value.
This gem creates a simple way to remove statements with null/blank values from query.
Very usefull for search forms avoiding you to worry about unfilled fields.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'where_unless_blank'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install where_unless_blank
## Usage
After install this gem three new methods will be available on `ActiveRecord::Base` instances.
`where_unless_blank`, `ilike_unless_blank` and `like_unless_blank`.
```
Person.where_unless_blank(age: params[:age]).ilike_unless_blank(name: params[:name])
Person.ilike_unless_blank(name: params[:name], surname: params[:surname])
Person.like_unless_blank(name: params[:name], surname: params[:surname])
```
If u like short names u can use:
`wub` or `where_ub` for `where_unless_blank`
`iub` or `ilike_ub` for `ilike_unless_blank`
`lub` or `like_ub` for `like_unless_blank`
If all params are blank it will behaivor like `all` method.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/platbr/where_unless_blank.