【发布时间】:2014-10-02 11:37:01
【问题描述】:
我在 application_controller.rb 中有 check_feature 方法
def self.check_feature(feature, options = {})
before_filter(options) { |controller| controller.check_feature_now(feature) }
end
def check_feature_now(feature)
raise MyError.new(401, I18n.t('exception.feature_not_enabled'), ErrorCodes::FEATURE_NOT_ENABLED) unless feature_enabled?(feature)
end
我将它用作过滤器(before_filter)。
在我的控制器中,我想说点什么,例如启用访问控制器的两个功能中的至少一个。
如果我这样做:
check_feature :feature1
check_feature :feature2
我需要启用功能 1 和功能 2 才能通过过滤器。
我想要类似的东西:
check_feature :feature1 || check_feature :feature2
有什么想法吗?
【问题讨论】:
-
控制器实例变量?看看这个:stackoverflow.com/questions/14413539/…
标签: ruby-on-rails ruby-on-rails-4 before-filter