Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6581335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:08:22+00:00 2026-05-25T16:08:22+00:00

I have the following in my model to search for a string entered by

  • 0

I have the following in my model to search for a string entered by a user:

def self.find_products(product="")

    find(:all, :select => 'product_id, name', :order => "name", :conditions => ["name like ? and locale =?", "%#{product.capitalize}%", I18n.locale])
  end

But it only works if the string is one word.
If the string contains two or more words such as “card guides” it returns nothing even if those are the exact words in the name.

How can I do this search properly.

Rails 3 Ruby 1.9.2

Update

It turns out that its a Postgresql syntax. I needed to user iLIKE for case insensitivity. Then it worked better. I still like the answer below as it also helped to refine my syntax.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:08:23+00:00Added an answer on May 25, 2026 at 4:08 pm

    Hey i am also using this type of search logic in mine project, I had done in this way . If you want to try then look if it might helps you -:

    class << self
       def search(query)
        product = "%#{query}%"
        where("name LIKE ? AND locale =?", product,I18n.locale)
       end
    end
    

    Thanks

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following method in my model: #find all the manufacturers names and
I have the following form: @model Teesa.Models.SearchModel @using (Html.BeginForm(Index, Search, FormMethod.Get, new { id
I have the following model: class User: name = models.CharField( max_length = 200 )
I have the following model setup - a User is interested in projects in
Right now I have the following code: @model IEnumerable<MvcAuction.Models.Furniture> @{ ViewBag.Title = Search; }
In the Photo model I have following simple rule: searchable do string :note end
I have the following in my View: @Html.DropDownListFor(model => model.Search, new SelectList(Model.SearchOptions)) In my
Suppose the following model : class Product include MongoMapper::Document key :name, String key :product_category_id,
In mongoose I've got this model: var userschema = new mongoose.Schema({ user: String, following:
I have a following view model and it will be used by a search

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.