[英]Routing error with has_scope
I am getting the error below with has_scope. 我收到以下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. 我在网站上的其他地方都拥有ActiveAdmin,并且相信可以使用它,因此我们可以假定gem正常运行。
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. 查看gem
has_scope
[ https://github.com/plataformatec/has_scope]的文档,看来您需要将:type
as :boolean
传递给控制器中的has_scope
方法。 This is applicable to the scopes that do not accept a parameter. 这适用于不接受参数的范围。
has_scope :upward_trending, :type => :boolean
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.