Search multiple models at once with Ransack

时间秒杀一切 提交于 2019-11-29 23:10:13

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, nil %>
<%= 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!