簡體   English   中英

創建裸導軌控制器類

[英]Create bare rails controller class

我正在嘗試基於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 method MetalController:Class 的block in <module:AssetPaths>': undefined method config_accessor' (NoMethodError)

軌道 4.1.0,紅寶石 2.1.0

更新:

如果我include ActiveSupport::Configurable

拋出錯誤:

_implied_layout_name': undefined local variable or method MetalController:Class (NameError) 的_implied_layout_name': undefined local variable or method controller_path'

您需要從ActionController::Metal繼承:

class MetalController < ActionController::Metal
  ActionController::Base.without_modules(:ParamsWrapper, :Streaming).each do |left|
    include left
  end
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM