JAML
JAML

Reputation: 215

Rails handle multiple Params in search query

I have the following model and I want to pass multiple params in "with_query", don't know how to achieve it. currently you can see it takes only "query" param. how can I filter it with country and job_type. any help would be really appreciated.

search Model

def self.search(query, country, job_type, page = 1)

      results = []

      Refinery.searchable_models.each do |model|
        results << model.limit(RESULTS_LIMIT).with_query(query)
      end if query.present?

      results.flatten[0..(RESULTS_LIMIT - 1)]

    end

Controller

  def show
    @results = Refinery::SearchEngine.search(params[:query], params[:country], params[:job_type], params[:page])
    present(@page = Refinery::Page.find_by_link_url("/search"))
  end

Upvotes: 0

Views: 297

Answers (1)

Edward
Edward

Reputation: 3499

I would try changing the line that builds your results in the search model to:

results << model.limit(RESULTS_LIMIT).with_query(query).where(country: country, job_type: job_type)

Upvotes: 1

Related Questions