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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:21:03+00:00 2026-05-27T16:21:03+00:00

Im trying to build advanced search finder for my Candidate model. Lets imagine it

  • 0

Im trying to build advanced search finder for my Candidate model.
Lets imagine it has couple fields + multiple associations like has_many: languages & has_many: skills. Now I’m building query like this:

query = Candidate.select("*")
if position_name
  query = query.where('position_name LIKE ? OR position_name IS NULL',"%#{position_name}%")
end 

if salary
  query = query.where('salary <= ? OR salary IS NULL',salary)
end

and so on…

Now I want to add more advanced conditions like to find users who only have such skills like PHP and Java (so return only those users who have both skills)

This works but only when I insert OR

  query = query.joins(:skills)
  query = query.where('`skills`.`name` = ? OR `skills`.`name` = ?',"Java","PHP")

Additionally I’d like the same also for languages (plus, language have language.name & language.level)

Can someone points me in which direction to look? And also how to build such condition where I can multiple skills or multiple languages?

  • 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-27T16:21:04+00:00Added an answer on May 27, 2026 at 4:21 pm

    Have a look at the various search gems like Ransack, Metawhere or Searchlogic

    http://rubygems.org/gems/ransack

    https://github.com/railsdog/searchlogic

    Both Ransack and Searchlogic allow searching on associated models and you can use scopes to restrict the search parameters.

    Example Search params for Searchlogic.

    [search][admitted_gte]  
    
    [search][admitted_lte]  
    
    [search][aetiology_like_any][]  VIRUS
    
    [search][at_risk_gte]   
    
    [search][at_risk_lte]   
    
    [search][died_gte]  
    
    [search][died_lte]  
    
    [search][gezi_reference_like]   
    
    [search][id]    
    
    [search][incidents_location_encrypted_postcode_like]    
    
    [search][lab_confirmed_gte] 
    
    [search][lab_confirmed_lte] 
    
    [search][onset_first_after] 
    
    [search][onset_first_before]    
    
    [search][onset_last_after]  
    
    [search][onset_last_before] 
    
    [search][outbreak_type_equals_any][]    FOODBORNE
    
    [search][point_source_date_after]   
    
    [search][point_source_date_before]  
    
    [search][total_affected_gte]    
    
    [search][total_affected_lte]    
    
    [search][user_reference_like]   
    
    [search][year_equals_any][] 2010
    
    search[order]   descend_by_id
    

    Outbreak_Controller.rb Index action returns the results of the Search query. From 17 Search params only a single searchlogic call is required @search = Outbreak.search(params[:search]). The params are whitelisted against a list of allowed search params – code not shown.

    def index
    
              #set the default index order to be descending Outbreak id
              if !params[:search][:order]
                  params[:search][:order] = "descend_by_id"  
              end
              if params[:search][:bacterial_agents_bacterium_name_like_any] != nil && !params[:search][:bacterial_agents_bacterium_name_like_any].empty?
                  params[:search][:bacterial_agents_category_like] = "CAUSATIVE"
              end
              if params[:search][:viral_agents_virus_name_like_any] != nil && !params[:search][:viral_agents_virus_name_like_any].empty?
                  params[:search][:viral_agents_category_like] = "CAUSATIVE"
              end
              if params[:search][:protozoal_agents_protozoa_name_like_any] != nil && !params[:search][:protozoal_agents_protozoa_name_like_any].empty?
                  params[:search][:protozoal_agents_category_like] = "CAUSATIVE"
              end
              if params[:search][:toxic_agents_toxin_name_like_any] != nil && !params[:search][:toxic_agents_toxin_name_like_any].empty?
                  params[:search][:toxic_agents_category_like] = "CAUSATIVE"
              end
      #Outbreak.search takes all of the given params and runs it against the Outbreak model and it's associated models
      @search = Outbreak.search(params[:search])
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a site-wide search with relevance, the site has around
I am trying to build an advance search option for our website. I am
I'm trying to build a custom search form for an e-commerce setup built on
I'm trying to add a 'Search' feature to my project. What I'd like to
I'm trying to build a little bit advanced users system using Joomla, but I
I build one search filter, in that filter users can filter using different fields
I am trying a Keyword search. I am looking in the fields ARTWORK_title and
Im trying to build a somewhat advanced "Flot" jQuery pluging graph. For that, I
I am trying to write active record queries in my model for an advanced
I am trying build a jQuery EasyUI datagrid or treegrid out of a large

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.