简体   繁体   中英

Routing error with has_scope

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]

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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