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 9323987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:28:54+00:00 2026-06-19T04:28:54+00:00

Using Rails and MySQL. Not sure if this has been asked, but couldn’t find

  • 0

Using Rails and MySQL. Not sure if this has been asked, but couldn’t find it.

I have the following records:

1. I love Rails
2. I love Django
3. I code using Ruby on Rails

====

(1) Search: “i love”

Results: “I love Rails”, “I love Django”

====

(2) Search: “love”

Results: “I love Rails”, “I love Django”

====

(3) Search: “ails”

Results: “I love Rails”, “I code using Ruby on Rails”

====

(4) Search: “code Ruby”

Results: “I code using Ruby on Rails”

====

My code is:

term = "%#{params[:term]}%"
shops = Shop.where("name LIKE ?", term)

It only works on Search (1) and (2). How can I code to achieve results when doing search (3) and (4) too?

Many thanks.

  • 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-06-19T04:28:55+00:00Added an answer on June 19, 2026 at 4:28 am

    Found the solution.

    I need to wrap each word in the search phrase with %string%.

    ====

    Search (1): “i love”

    Query: SELECT * from t WHERE name LIKE "%i% %love%";

    Results: “I love Rails”, “I love Django”

    ====

    Search (2): “love”

    Query: SELECT * from t WHERE name LIKE "%love%";

    Results: “I love Rails”, “I love Django”

    ====

    Search (3): “ails”

    Query: SELECT * from t WHERE name LIKE "%ails%";

    Results: “I love Rails”, “I code using Ruby on Rails”

    ====

    Search (4): “code Ruby”

    Query: SELECT * from t WHERE name LIKE "%code% %Ruby%";

    Results: “I code using Ruby on Rails”

    ====

    My Ruby code should be:

    term = "#{params[:term]}"
    f_term = term.gsub /\b/, '%'
    shops = Shop.where("name LIKE ?", f_term)
    

    You can test this at http://sqlfiddle.com/#!2/d63f5/4

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

Sidebar

Related Questions

I have a deployment using: rails 2.3.2 ruby 1.8.7 mysql db and 3 mongrel
I am using Ruby on Rails 3.2.2 and MySQL. I have a method (an
I am not sure what causes this error but since I came across this
I'm using rails 3.0 and MySql 5.1 I have these three models: Question, Tag
I get this error when running rails with mysql db. Basically it is not
I am following this backbone rails turotial . The tutorial says they are using
I'm very new to Ruby on Rails, and have been getting the following error
I'm not sure how to find what I'm looking for here, but I've cloned
I'm pretty sure that this has to do with my setup but let me
I want this SQL query to be written in rails controller using find: select

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.