2
votes

I have a Rails application which uses ransack to make search. I think my question its simple, I like to make one form search work with multiple models.

There is my code:

SearchController:

class SearchController < SuperSiteController
  def index
    @q = Page.ransack(params[:q])
    @result = @q.result(distinct: true)
  end

  def search
    index
    render :index
  end
end

My form:

<%= search_form_for @q, url: search_path, html: { method: :post } do |f| %>
    <%= f.search_field :name_cont, placeholder: "BUSCAR", required: true %>
<% end %>

I didn't find anything in documentation about the best way to do that. How can I do this?

1
Thank you, but these models has no association with each other. - Fernando Aureliano

1 Answers

1
votes

I think the best solution is - using pgsearch gem xD

This gem represents the ability to search in several models at once.

https://github.com/Casecommons/pg_search#multi-search