我在运行 pg_search 时遇到问题。我认为它设置正确,但由于某种原因,在尝试运行搜索时,会出现以下情况:
SQLite3::SQLException: unrecognized token: ":": SELECT "courses".*, ((ts_rank((to_tsvector('simple',
coalesce("courses"."title"::text, ''))), (to_tsquery('simple', ''' ' || 'finance' || ' ''')), 0))) AS
pg_search_rank FROM "courses" WHERE (((to_tsvector('simple', coalesce("courses"."title"::text, '')))
@@ (to_tsquery('simple', ''' ' || 'finance' || ' ''')))) ORDER BY pg_search_rank DESC, "courses"."id" ASC
课程模式:
include PgSearch
scope :by_course_title, lambda { |ttl|
_by_course_title(ttl) if ttl.present? }
pg_search_scope :_by_course_title, against: :title
搜索控制器:
def index
@course = Course.by_course_title(params[:fname])
end
在 html 中:
<% @course.each do |courses| %>
<div><%= courses %></div>
<% end %>
这可能是由.each引起的吗?如果我只保留 <%= @course %>,页面会加载并显示:
#<ActiveRecord::Relation:0x....>
我应该在传递 .each 函数之前转换结果数组吗?