Rails 4 postgres full text search error (in brackets)

I followed railscast in full-text search with postgres, but I keep getting the following error

undefined local variable or `scoped 'method for #

Ive been watching the railscast for sure . I have all the right stones installed. (pg_search, pg). Here is my code

Article controller (I also use act_as_taggable here)

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 at 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 noticed between the railscast code and mine is that hes using will_paginate, but when I change the controller to

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

it does not matter.

I searched almost everywhere, but to no avail.

+4
1

scoped . all.

+14

Source: https://habr.com/ru/post/1542055/


All Articles