0

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 関数を渡す前に、結果の配列を変換する必要がありますか?

4

1 に答える 1