Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# Let's say I have the following user.
user = User.create(:company_name => "The cheappo restaurant")
# And the following User finder that works with `starting_with`.
def self.find_all_by_indexed_company_name(term) do |q|
q.text_fields { with(:company_name).starting_with(term) }
# Now let's try some queries
=> user
User.find_all_by_indexed_company_name("the ch")
=> user
# Now if I search for "estaurant"
=> []
# This is why I say `starting_with` partially works for me,
# I would like to have an indexed search using something like `LIKE`:
User.find(:all, :conditions => ["company_name LIKE ?", "%estaurant%"])
=> user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment