gpt4 book ai didi

ruby-on-rails - rails 5 : Search multiple models with Ransack

转载 作者:太空宇宙 更新时间:2023-11-03 16:14:00 26 4
gpt4 key购买 nike

我有一个使用 ransack 的 Rails 应用程序进行搜索。我认为我的问题很简单,我喜欢使一个表单搜索适用于多个模型。

这是我的代码:

搜索 Controller :

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

def search
index
render :index
end
end

我的表单:

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

我没有在文档中找到任何有关执行该操作的最佳方法的信息。我该怎么做?

最佳答案

我认为最好的解决方案是 - 使用 pgsearch gem xD

这个 gem 代表了同时搜索多个模型的能力。

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

关于ruby-on-rails - rails 5 : Search multiple models with Ransack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52559675/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com