5

Ive been following the railscast on full text search with postgres but I keep getting the following error

undefined local variable or method `scoped' for #

Ive followed the railscast exactly. I have all the correct gems installed. (pg_search, pg). Here is my code

article controller (I'm also using acts_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 on 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

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

it makes no difference.

Ive searched pretty much everywhere but to no avail.

Yesthe Cia
  • 528
  • 1
  • 7
  • 20
  • Did not you got any *deprecated warning*. See this - http://apidock.com/rails/ActiveRecord/Associations/Association/scoped and http://apidock.com/rails/ActiveRecord/NamedScope/ClassMethods/scoped – Arup Rakshit May 26 '14 at 15:28
  • I suggest you use a debugging tool such as the `byebug` gem or the Rails `debugger` and stick them in both your `index` action and your `text_search` method. – vich May 26 '14 at 15:32

1 Answers1

16

scoped has been removed. Try all instead.

Buck Doyle
  • 6,333
  • 1
  • 22
  • 35
  • 1
    That gets rid of the error however when I put in a search I get all the articles. I'll mark this as accepted since it answers my question but any idea why searches are returning all? – Yesthe Cia May 26 '14 at 21:44