简体   繁体   English

Rails 4 postgres全文搜索错误(范围)

[英]Rails 4 postgres full text search error (scoped)

Ive been following the railscast on full text search with postgres but I keep getting the following error 我一直在跟踪postgres全文搜索的railscast,但我一直收到以下错误

undefined local variable or method `scoped' for # 未定义的局部变量或方法`scoped'for#

Ive followed the railscast exactly. 我完全按照轨道直播 I have all the correct gems installed. 我安装了所有正确的宝石。 (pg_search, pg). (pg_search,pg)。 Here is my code 这是我的代码

article controller (I'm also using acts_as_taggable here) 文章控制器(我也在这里使用acts_as_taggable)

def index

   @articles = Article.text_search(params[:query]).page(params[:page]).per_page(3)

   if params[:tag]
      @articles = Article.tagged_with(params[:tag])
   else
      @articles = Article.all
   end
end

article model 文章模型

def self.text_search(query)
  if query.present?
    where("name @@ :q or content @@ :q", q: query)
  else
   scoped
  end
end

And the form on Article/index 和Article / index上的表格

<%= form_tag articles_path, method: :get do %>
  <p>
    <%= text_field_tag :query, params[:query] %>
    <%= submit_tag "Search", name: nil %>
  </p>
<% end %>

The only difference I noted between the railscast code and mine is that hes using will_paginate but when I change the controller to 我在railscast代码和我之间注意到的唯一区别是他使用了will_paginate,但当我将控制器更改为

@articles = Article.text_search(params[:query])

it makes no difference. 没什么区别。

Ive searched pretty much everywhere but to no avail. 我几乎到处搜索但无济于事。

scoped has been removed. scoped已被删除。 Try all instead. all尝试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM