Skip to content

An easy way to write LIKE / ILIKE queries for Active Record models

License

Notifications You must be signed in to change notification settings

amitree/activerecord_search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

activerecord_search

This gem extends the ActiveRecord predicate builder to allow writing LIKE/ILIKE queries without writing raw SQL.

Usage

Add to your Gemfile:

gem 'activerecord_search'

Then you can write queries like this:

users = User.where(name: Search('ji'))
  # Returns users "Jim" and "Benji"
users = User.where(name: Search(ends_with: 'ji'))
  # Returns user "Benji"
users = User.where(name: Search(starts_with: 'ji'))
  # Find user "Jim"
users = User.where(name: Search(like: 'b%i'))
  # Find users "Benji" and "Banh Mi"

Internally, it uses the Arel matches node, which becomes ILIKE for Postgres and LIKE for other databases. In general, this should be case insensitive.

About

An easy way to write LIKE / ILIKE queries for Active Record models

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages