存储在数据库洗劫搜索字符串数组 [英] Ransack search string arrays stored in db
本文介绍了存储在数据库洗劫搜索字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用洗劫的文章进行搜索。
I'm trying to search using ransack for articles.
在我如何根据自己的标签来获取文章的问题之一,我发现了如何做到这一点:
In one of my question in how to get the articles based on their tags, I found out how to do so:
现在我只想做洗劫搜索,但我得到一个错误
Now I just want to do the search with ransack but I get an error
我有这样的
<%= search_form_for @q do |f| %>
<div class="row">
<div class="col-md-2">
<%= f.label :tags_in %> <span data-toggle='tooltip', data-placement='right', title='Una o dos palabras máximo para expecificar lo que está buscando' class="glyphicon glyphicon-question-sign" ></span>
<%= f.search_field :tags_in, class: 'form-control' %>
</div>
<div class="col-md-2">
<%= f.submit 'Buscar', class: 'btn btn-primary m-t-large' %>
</div>
</div>
<% end %>
为的Xbox
执行此搜索时,我得到的错误是:
the error I get when performing this searching for xbox
is the following:
PG::InvalidTextRepresentation: ERROR: array value must start with "{" or dimension information
LINE 1: ...es".* FROM "articles" WHERE "articles"."tags" IN ('xbox') O...
继承人的控制器:
def index
@q = Article.ransack(params[:q])
@articles = @q.result.paginate(page: params[:page], :per_page => 10).order('created_at DESC')
end
我如何可以使用其标签搜索文章?
How can I search for the articles using their tags?
谢谢!
推荐答案
由于在这个讨论问题您需要添加宝石 postgres_ext 到您的项目:
As discussed on this issue you need to add the gem postgres_ext to your project:
# Gemfile
gem 'postgres_ext'
和它添加到一个初始化:
And add this to an initializer:
# config/initializers/ransack.rb
Ransack.configure do |config|
%w[
contained_within
contained_within_or_equals
contains
contains_or_equals
overlap
].each do |p|
config.add_predicate p, arel_predicate: p, wants_array: true
end
end
之后,您就可以使用包含
在一个序列化的阵列。
这篇关于存储在数据库洗劫搜索字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文