Elliot
Elliot

Reputation: 13835

basic text search in rails 3 and mongo db (mongoid)

I have some nifty javascript that serializes search input.

the controller has this:

@recipes = Recipe.where(name: params[:q])

right now it only returns results when theres an exact full word match - does anyone know of a way to make it return results which might contain the params[:q] even if its not an exact full match?

i.e. chicken should return chicken stew, chicken pot pie, etc.

Upvotes: 1

Views: 599

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230286

Try this one:

@recipes = Recipe.where(name: /#{params[:q]}/i)

Upvotes: 3

Related Questions