aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/caching/sweeping.rb2
-rw-r--r--actionpack/lib/action_controller/http.rb134
-rw-r--r--actionpack/lib/action_controller/metal/helpers.rb1
-rw-r--r--actionpack/lib/action_controller/railtie.rb22
-rw-r--r--actionpack/lib/action_controller/railties/helpers.rb22
-rw-r--r--actionpack/lib/action_controller/railties/paths.rb24
-rw-r--r--actionpack/lib/action_controller/test_case.rb5
7 files changed, 35 insertions, 175 deletions
diff --git a/actionpack/lib/action_controller/caching/sweeping.rb b/actionpack/lib/action_controller/caching/sweeping.rb
index 49cf70ec21..808a6fe5f3 100644
--- a/actionpack/lib/action_controller/caching/sweeping.rb
+++ b/actionpack/lib/action_controller/caching/sweeping.rb
@@ -88,7 +88,7 @@ module ActionController #:nodoc:
end
def method_missing(method, *arguments, &block)
- return unless @controller
+ super unless @controller
@controller.__send__(method, *arguments, &block)
end
end
diff --git a/actionpack/lib/action_controller/http.rb b/actionpack/lib/action_controller/http.rb
deleted file mode 100644
index 252a652cd9..0000000000
--- a/actionpack/lib/action_controller/http.rb
+++ /dev/null
@@ -1,134 +0,0 @@
-require "action_controller/log_subscriber"
-
-module ActionController
- # HTTP Controller is a lightweight version of <tt>ActionController::Base</tt>,
- # created for applications that don't require all functionality that a complete
- # \Rails controller provides, allowing you to create faster controllers. The
- # main scenario where HTTP Controllers could be used is API only applications.
- #
- # An HTTP Controller is different from a normal controller in the sense that
- # by default it doesn't include a number of features that are usually required
- # by browser access only: layouts and templates rendering, cookies, sessions,
- # flash, assets, and so on. This makes the entire controller stack thinner and
- # faster, suitable for API applications. It doesn't mean you won't have such
- # features if you need them: they're all available for you to include in
- # your application, they're just not part of the default HTTP Controller stack.
- #
- # By default, only the ApplicationController in a \Rails application inherits
- # from <tt>ActionController::HTTP</tt>. All other controllers in turn inherit
- # from ApplicationController.
- #
- # A sample controller could look like this:
- #
- # class PostsController < ApplicationController
- # def index
- # @posts = Post.all
- # render json: @posts
- # end
- # end
- #
- # Request, response and parameters objects all work the exact same way as
- # <tt>ActionController::Base</tt>.
- #
- # == Renders
- #
- # The default HTTP Controller stack includes all renderers, which means you
- # can use <tt>render :json</tt> and brothers freely in your controllers. Keep
- # in mind that templates are not going to be rendered, so you need to ensure
- # your controller is calling either <tt>render</tt> or <tt>redirect</tt> in
- # all actions.
- #
- # def show
- # @post = Post.find(params[:id])
- # render json: @post
- # end
- #
- # == Redirects
- #
- # Redirects are used to move from one action to another. You can use the
- # <tt>redirect</tt> method in your controllers in the same way as
- # <tt>ActionController::Base</tt>. For example:
- #
- # def create
- # redirect_to root_url and return if not_authorized?
- # # do stuff here
- # end
- #
- # == Adding new behavior
- #
- # In some scenarios you may want to add back some functionality provided by
- # <tt>ActionController::Base</tt> that is not present by default in
- # <tt>ActionController::HTTP</tt>, for instance <tt>MimeResponds</tt>. This
- # module gives you the <tt>respond_to</tt> and <tt>respond_with</tt> methods.
- # Adding it is quite simple, you just need to include the module in a specific
- # controller or in <tt>ApplicationController</tt> in case you want it
- # available to your entire app:
- #
- # class ApplicationController < ActionController::HTTP
- # include ActionController::MimeResponds
- # end
- #
- # class PostsController < ApplicationController
- # respond_to :json, :xml
- #
- # def index
- # @posts = Post.all
- # respond_with @posts
- # end
- # end
- #
- # Quite straightforward. Make sure to check <tt>ActionController::Base</tt>
- # available modules if you want to include any other functionality that is
- # not provided by <tt>ActionController::HTTP</tt> out of the box.
- class HTTP < Metal
- abstract!
-
- # Shortcut helper that returns all the ActionController::HTTP modules except the ones passed in the argument:
- #
- # class MetalController
- # ActionController::HTTP.without_modules(:ParamsWrapper, :Streaming).each do |left|
- # include left
- # end
- # end
- #
- # 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.
- def self.without_modules(*modules)
- modules = modules.map do |m|
- m.is_a?(Symbol) ? ActionController.const_get(m) : m
- end
-
- MODULES - modules
- end
-
- MODULES = [
- HideActions,
- UrlFor,
- Redirecting,
- Rendering,
- Renderers::All,
- ConditionalGet,
- RackDelegation,
-
- ForceSSL,
- DataStreaming,
-
- # Before callbacks should also be executed the earliest as possible, so
- # also include them at the bottom.
- AbstractController::Callbacks,
-
- # Append rescue at the bottom to wrap as much as possible.
- Rescue,
-
- # Add instrumentations hooks at the bottom, to ensure they instrument
- # all the methods properly.
- Instrumentation
- ]
-
- MODULES.each do |mod|
- include mod
- end
-
- ActiveSupport.run_load_hooks(:action_controller, self)
- end
-end
diff --git a/actionpack/lib/action_controller/metal/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb
index d070eaae5d..1a4bca12d2 100644
--- a/actionpack/lib/action_controller/metal/helpers.rb
+++ b/actionpack/lib/action_controller/metal/helpers.rb
@@ -52,6 +52,7 @@ module ActionController
module Helpers
extend ActiveSupport::Concern
+ class << self; attr_accessor :helpers_path; end
include AbstractController::Helpers
included do
diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb
index 5e837ca6e1..851a2c4aee 100644
--- a/actionpack/lib/action_controller/railtie.rb
+++ b/actionpack/lib/action_controller/railtie.rb
@@ -3,33 +3,32 @@ require "action_controller"
require "action_dispatch/railtie"
require "action_view/railtie"
require "abstract_controller/railties/routes_helpers"
-require "action_controller/railties/paths"
+require "action_controller/railties/helpers"
module ActionController
class Railtie < Rails::Railtie #:nodoc:
config.action_controller = ActiveSupport::OrderedOptions.new
- initializer "action_controller.logger" do
- ActiveSupport.on_load(:action_controller) { self.logger ||= Rails.logger }
- end
-
- initializer "action_controller.initialize_framework_caches" do
- ActiveSupport.on_load(:action_controller) { self.cache_store ||= Rails.cache if respond_to?(:cache_store) }
- end
-
initializer "action_controller.assets_config", :group => :all do |app|
app.config.action_controller.assets_dir ||= app.config.paths["public"].first
end
+ initializer "action_controller.set_helpers_path" do |app|
+ ActionController::Helpers.helpers_path = app.helpers_paths
+ end
+
initializer "action_controller.set_configs" do |app|
paths = app.config.paths
options = app.config.action_controller
+ options.logger ||= Rails.logger
+ options.cache_store ||= Rails.cache
+
options.javascripts_dir ||= paths["public/javascripts"].first
options.stylesheets_dir ||= paths["public/stylesheets"].first
options.page_cache_directory ||= paths["public"].first
- # make sure readers methods get compiled
+ # Ensure readers methods get compiled
options.asset_path ||= app.config.asset_path
options.asset_host ||= app.config.asset_host
options.relative_url_root ||= app.config.relative_url_root
@@ -37,7 +36,8 @@ module ActionController
ActiveSupport.on_load(:action_controller) do
include app.routes.mounted_helpers
extend ::AbstractController::Railties::RoutesHelpers.with(app.routes)
- extend ::ActionController::Railties::Paths.with(app) if respond_to?(:helpers_path)
+ extend ::ActionController::Railties::Helpers
+
options.each do |k,v|
k = "#{k}="
if respond_to?(k)
diff --git a/actionpack/lib/action_controller/railties/helpers.rb b/actionpack/lib/action_controller/railties/helpers.rb
new file mode 100644
index 0000000000..3985c6b273
--- /dev/null
+++ b/actionpack/lib/action_controller/railties/helpers.rb
@@ -0,0 +1,22 @@
+module ActionController
+ module Railties
+ module Helpers
+ def inherited(klass)
+ super
+ return unless klass.respond_to?(:helpers_path=)
+
+ if namespace = klass.parents.detect { |m| m.respond_to?(:railtie_helpers_paths) }
+ paths = namespace.railtie_helpers_paths
+ else
+ paths = ActionController::Helpers.helpers_path
+ end
+
+ klass.helpers_path = paths
+
+ if klass.superclass == ActionController::Base && ActionController::Base.include_all_helpers
+ klass.helper :all
+ end
+ end
+ end
+ end
+end
diff --git a/actionpack/lib/action_controller/railties/paths.rb b/actionpack/lib/action_controller/railties/paths.rb
deleted file mode 100644
index 7e79b036ed..0000000000
--- a/actionpack/lib/action_controller/railties/paths.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-module ActionController
- module Railties
- module Paths
- def self.with(app)
- Module.new do
- define_method(:inherited) do |klass|
- super(klass)
-
- if namespace = klass.parents.detect { |m| m.respond_to?(:railtie_helpers_paths) }
- paths = namespace.railtie_helpers_paths
- else
- paths = app.helpers_paths
- end
- klass.helpers_path = paths
-
- if klass.superclass == ActionController::Base && ActionController::Base.include_all_helpers
- klass.helper :all
- end
- end
- end
- end
- end
- end
-end
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index 7af30ed690..7ba8319e4c 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -505,11 +505,6 @@ module ActionController
end
end
- # Cause the action to be rescued according to the regular rules for rescue_action when the visitor is not local
- def rescue_action_in_public!
- @request.remote_addr = '208.77.188.166' # example.com
- end
-
included do
include ActionController::TemplateAssertions
include ActionDispatch::Assertions