【发布时间】:2014-04-09 11:55:07
【问题描述】:
我正在尝试基于ActionController::Base 创建干净的控制器。这就是我尝试的方法:
class MetalController
ActionController::Base.without_modules(:ParamsWrapper, :Streaming).each do |left|
include left
end
end
来自 Rails 文档:
返回包含在 ActionController::Base 除了作为参数传递的那些:
这可以更好地控制您要排除的内容并使其 更容易创建一个裸控制器类,而不是列出模块 手动需要。
我的另一个控制器继承自MetalController:
class API::BaseController < MetalController
#.... my awesome api code
end
所以这不起作用然后我启动rails server:
block in <module:AssetPaths>': undefined methodconfig_accessor' 为 MetalController:Class (NoMethodError)
Rails 4.1.0、Ruby 2.1.0
更新:
如果我include ActiveSupport::Configurable
抛出错误:
_implied_layout_name': undefined local variable or methodcontroller_path' 用于 MetalController:Class (NameError)
【问题讨论】:
-
您是否尝试将
include ActiveSupport::Configurable添加到您的 MetalController(在每个循环之前)? -
@BroiSatse 不起作用(。查看更新问题
标签: ruby-on-rails ruby api actioncontroller