🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

activerecord_search

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

activerecord_search

1.2
Rubygems
Version published
Maintainers
1
Created
Source

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.

FAQs

Package last updated on 16 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts