Skip to content

Instantly share code, notes, and snippets.

@mattraykowski
Created September 15, 2014 18:28
Show Gist options
  • Save mattraykowski/55fb15638b268c797479 to your computer and use it in GitHub Desktop.
Save mattraykowski/55fb15638b268c797479 to your computer and use it in GitHub Desktop.
Testing safe_like out.
[7] pry(main)> person.last_name
=> "Raykowski"
[8] pry(main)> Person.safe_like(:last_name, "ray%")
Person Load (1.7ms) SELECT "people".* FROM "people" WHERE "people"."site_id" = 1 AND ("people"."last_name" ILIKE 'ray%')
=> [<1:Matt Raykowski>]
[9] pry(main)> Person.where(first_name: 'Matt')
Person Load (1.2ms) SELECT "people".* FROM "people" WHERE "people"."site_id" = 1 AND "people"."first_name" = 'Matt'
=> [<1:Matt Raykowski>]
[10] pry(main)> Person.where(first_name: 'Matt').safe_like(:last_name, 'ray%')
Person Load (1.1ms) SELECT "people".* FROM "people" WHERE "people"."site_id" = 1 AND "people"."first_name" = 'Matt' AND ("people"."last_name" ILIKE 'ray%')
=> [<1:Matt Raykowski>]
[11] pry(main)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment