ruby on rails - Search multiple models at once with Ransack

ID : 274345

viewed : 40

Tags : ruby-on-railsrubysearchransackruby-on-railsruby





Top 2 Answer for ruby on rails - Search multiple models at once with Ransack

vote vote

96

Okay, after asking the question the answer popped into my head.

Instead of the search_form_for helper I'm now just using the form_tag helper in the following way:

<%= form_tag search_path, method: :get do %>   <%= text_field_tag :q, params[:q] %> <%= end %> 

and in the search action I just do:

q = params[:q] @works    = Work.search(name_cont: q).result @projects = Project.search(name_cont: q).result @users    = User.search(name_cont: q).result 

This works for me. I hope this also helps someone else.

vote vote

83

Top 3 video Explaining ruby on rails - Search multiple models at once with Ransack







Related QUESTION?