小编Abr*_*han的帖子

在关注中定义的覆盖范围内调用 super

我希望将附加查询链接到模型中的范围。范围在关注中定义。

module Companyable
    extend ActiveSupport::Concern

    included do
        scope :for_company, ->(id) {
            where(:company_id => id)
        }
    end
end


class Order < ActiveRecord::Base
    include Companyable

    # I'd like to be able to do something like this:
    scope :for_company, ->(id) {
        super(id).where.not(:status => 'cancelled')
    }
end
Run Code Online (Sandbox Code Playgroud)

然而,这可以理解地抛出一个 NameError: undefined method 'for_company' for class 'Order'

ruby-on-rails-4

5
推荐指数
1
解决办法
838
查看次数

标签 统计

ruby-on-rails-4 ×1