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

  • Home
  • SEARCH
  • 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 890009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:39:30+00:00 2026-05-15T13:39:30+00:00

Hey, I got a find condition that is a bit lengthy and I’d like

  • 0

Hey, I got a find condition that is a bit lengthy and I’d like make it lengthier.

SO far

:conditions =>  ["name LIKE ? OR description LIKE ?", "%#{params[:search_keyword]}%",
        "%#{params[:search_keyword]}%"]

Where it’s searching the model for if the attribute :name or :description is like a param from a text box. Now I’d also like to add to make sure the entries found are current. I already have

:conditions => ["start_date between ? and ? ", Date.today, @yearstime ]

Where @yearstime is @yearstime = Date.today + 365.days so essentially everything thing in the model from the present date to a year from now

I’d like to combine both conditions but am unsure of the syntax. I tried to put it all together.

:conditions =>  ["name LIKE ? OR description LIKE ? AND start_date between ? and ?",
 "%#{params[:search_keyword]}%", "%#{params[:search_keyword]}%", Date.today, @yearstime ]

but it still isn’t calculating for the date parameter….Any idea what I’m doing wrong?

  • 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-15T13:39:31+00:00Added an answer on May 15, 2026 at 1:39 pm

    Looks like it’s probably an order of operators issue. Try

    :conditions =>  ["(name LIKE ? OR description LIKE ?) AND (start_date between ? and ?)",
     "%#{params[:search_keyword]}%", "%#{params[:search_keyword]}%", Date.today, @yearstime ]
    

    The AND operator has a higher precedence than OR

    Reference:

    • http://dev.mysql.com/doc/refman/5.1/en/operator-precedence.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everyone, got a quick question that I can't seem to find anything about...
Hey everyone I got a javascript problem I can't seem to find a specific
Hey! I've got a generic package that requires a config file and multiple packages
Hey all, here's the deal... I've got a UIImage that is being loaded in
Hey, I've got an element that does a requestAction to grab records sorted by
I've got this method I'm working on (I think that's the name) and it
Hey there, I've got a block of HTML that I'm going to be using
Hey. I've got some code from Agile Web Development that wraps some HTML around
Hey, I've got this nice little piece of code, much like all the other
Hey. I've got a QListView, and so far I've only figured out how to

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.