2

I am getting the error below with has_scope. This seems like a really obvious and basic error but I just can't work it out. I'd really appreciate any help that can be offered.

I have got ActiveAdmin elsewhere on the site and I believe that uses it so we can assume the gem is operating correctly.

ActionController::RoutingError at /products
undefined method `has_scope' for ProductsController:Class

Model:

class Product < ActiveRecord::Base
    belongs_to :category

    # Scopes
    default_scope { order('end_date DESC') } 
    scope :upward_trending, -> { where( "status > ?", 100).order('end_date DESC') }
end

Controller:

class ProductsController < ApplicationController
    before_filter :authenticate_user!

    has_scope :upward_trending

    def product_params
        params.require(:product).permit(:name, :status)
    end

    def index
        @q = Product.search(params[:q])
        @products = apply_scopes(@q.result.page(params[:page]).per(5)).all
    end


    def show
    end

end

Routes:

resources :products, only: [:index]
infused
  • 24,000
  • 13
  • 68
  • 78
bnussey
  • 1,894
  • 1
  • 19
  • 34

1 Answers1

0

Looking at the documentation of the gem has_scope[https://github.com/plataformatec/has_scope], it looks like you need to pass in :type as :boolean to has_scope method in the controller. This is applicable to the scopes that do not accept a parameter.

has_scope :upward_trending, :type => :boolean
San
  • 1,954
  • 1
  • 14
  • 18
  • Great pick up, thank you for that. Unfortunately I am still getting the same error :( Any other ideas – bnussey Nov 12 '14 at 19:11
  • From the error, it does look like the gem is not being loaded as @BroiSatse suggested. Try stopping and restarting the server if you haven't already. – San Nov 12 '14 at 20:10