2

I'm trying to create clean controller based on ActionController::Base. That's what I try:

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

From Rails doc:

Shortcut helper that returns all the modules included in ActionController::Base except the ones passed as arguments:

This gives better control over what you want to exclude and makes it easier to create a bare controller class, instead of listing the modules required manually.

My another controller inherits from MetalController :

class API::BaseController < MetalController
  #.... my awesome api code
end

So this not work then i launch rails server:

block in <module:AssetPaths>': undefined methodconfig_accessor' for MetalController:Class (NoMethodError)

Rails 4.1.0, Ruby 2.1.0

Update:

If i include ActiveSupport::Configurable

throws the errors:

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

Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103

1 Answers1

2

You need to inherit from ActionController::Metal:

class MetalController < ActionController::Metal
  ActionController::Base.without_modules(:ParamsWrapper, :Streaming).each do |left|
    include left
  end
end
BroiSatse
  • 44,031
  • 8
  • 61
  • 86
  • i dont think so, because order in `ActionController::Base::MODULES` look same as `ActionController::Base.without_modules(:ParamsWrapper, :Streaming)`. i know about `.ancestors`, thank for you solutions but i have same errors. – Roman Kiselenko Apr 09 '14 at 12:38
  • Hmmm. It is running for me without any problems. – BroiSatse Apr 09 '14 at 12:39
  • Sorry i have another errors `_implied_layout_name': undefined local variable or method `controller_path' for MetalController:Class` after you solutions, have idea? – Roman Kiselenko Apr 09 '14 at 12:40
  • You need to inherit from AbstractController::Base as well. I'll update answer. – BroiSatse Apr 09 '14 at 12:44
  • 1
    i found solution i need inherit from `ActionController::Metal` if i use `AbstractController::Base` instead my controller ```raise undefined method `action'``` – Roman Kiselenko Apr 09 '14 at 12:48
  • Awesome. I'll delete this answer, please post yours. :) – BroiSatse Apr 09 '14 at 12:49