2017-07-24 20:20:53 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2009-12-31 20:28:48 +00:00
|
|
|
require "rails"
|
2010-02-26 00:48:36 +00:00
|
|
|
require "action_controller"
|
2010-03-26 17:47:55 +00:00
|
|
|
require "action_dispatch/railtie"
|
2010-08-02 15:38:44 +00:00
|
|
|
require "abstract_controller/railties/routes_helpers"
|
2017-10-21 13:18:17 +00:00
|
|
|
require "action_controller/railties/helpers"
|
2013-12-22 21:54:51 +00:00
|
|
|
require "action_view/railtie"
|
2009-12-31 19:46:56 +00:00
|
|
|
|
2009-12-23 22:55:12 +00:00
|
|
|
module ActionController
|
2012-02-29 18:44:45 +00:00
|
|
|
class Railtie < Rails::Railtie #:nodoc:
|
2010-03-26 17:47:55 +00:00
|
|
|
config.action_controller = ActiveSupport::OrderedOptions.new
|
2010-02-26 00:48:36 +00:00
|
|
|
|
2012-08-01 18:54:22 +00:00
|
|
|
config.eager_load_namespaces << ActionController
|
|
|
|
|
2016-08-06 17:35:13 +00:00
|
|
|
initializer "action_controller.assets_config", group: :all do |app|
|
2012-01-10 18:33:26 +00:00
|
|
|
app.config.action_controller.assets_dir ||= app.config.paths["public"].first
|
|
|
|
end
|
|
|
|
|
2012-03-15 07:48:38 +00:00
|
|
|
initializer "action_controller.set_helpers_path" do |app|
|
|
|
|
ActionController::Helpers.helpers_path = app.helpers_paths
|
|
|
|
end
|
|
|
|
|
2012-08-30 21:36:59 +00:00
|
|
|
initializer "action_controller.parameters_config" do |app|
|
2013-01-19 17:32:27 +00:00
|
|
|
options = app.config.action_controller
|
|
|
|
|
2017-08-03 20:20:52 +00:00
|
|
|
ActiveSupport.on_load(:action_controller, run_once: true) do
|
2017-07-04 19:32:26 +00:00
|
|
|
ActionController::Parameters.permit_all_parameters = options.delete(:permit_all_parameters) { false }
|
|
|
|
if app.config.action_controller[:always_permitted_parameters]
|
|
|
|
ActionController::Parameters.always_permitted_parameters =
|
|
|
|
app.config.action_controller.delete(:always_permitted_parameters)
|
|
|
|
end
|
|
|
|
ActionController::Parameters.action_on_unpermitted_parameters = options.delete(:action_on_unpermitted_parameters) do
|
|
|
|
(Rails.env.test? || Rails.env.development?) ? :log : false
|
2017-07-04 20:09:00 +00:00
|
|
|
end
|
2013-01-19 17:32:27 +00:00
|
|
|
end
|
2012-08-30 21:36:59 +00:00
|
|
|
end
|
|
|
|
|
2010-07-23 22:48:12 +00:00
|
|
|
initializer "action_controller.set_configs" do |app|
|
2010-08-23 16:31:29 +00:00
|
|
|
paths = app.config.paths
|
|
|
|
options = app.config.action_controller
|
|
|
|
|
2013-01-19 17:32:27 +00:00
|
|
|
options.logger ||= Rails.logger
|
|
|
|
options.cache_store ||= Rails.cache
|
2012-03-15 07:48:38 +00:00
|
|
|
|
2013-01-19 17:32:27 +00:00
|
|
|
options.javascripts_dir ||= paths["public/javascripts"].first
|
|
|
|
options.stylesheets_dir ||= paths["public/stylesheets"].first
|
2010-08-23 16:31:29 +00:00
|
|
|
|
2017-03-11 13:17:44 +00:00
|
|
|
# Ensure readers methods get compiled.
|
2013-01-19 17:32:27 +00:00
|
|
|
options.asset_host ||= app.config.asset_host
|
|
|
|
options.relative_url_root ||= app.config.relative_url_root
|
2010-09-27 12:50:39 +00:00
|
|
|
|
2010-03-30 00:08:08 +00:00
|
|
|
ActiveSupport.on_load(:action_controller) do
|
2010-09-06 18:47:25 +00:00
|
|
|
include app.routes.mounted_helpers
|
2010-08-06 14:34:48 +00:00
|
|
|
extend ::AbstractController::Railties::RoutesHelpers.with(app.routes)
|
2012-03-15 07:48:38 +00:00
|
|
|
extend ::ActionController::Railties::Helpers
|
|
|
|
|
2016-10-29 03:05:58 +00:00
|
|
|
options.each do |k, v|
|
2012-03-13 19:21:41 +00:00
|
|
|
k = "#{k}="
|
|
|
|
if respond_to?(k)
|
|
|
|
send(k, v)
|
|
|
|
elsif !Base.respond_to?(k)
|
|
|
|
raise "Invalid option key: #{k}"
|
|
|
|
end
|
|
|
|
end
|
2010-03-07 14:24:30 +00:00
|
|
|
end
|
2010-07-23 22:48:12 +00:00
|
|
|
end
|
2010-09-27 12:50:39 +00:00
|
|
|
|
2010-09-27 18:42:02 +00:00
|
|
|
initializer "action_controller.compile_config_methods" do
|
2010-09-27 12:50:39 +00:00
|
|
|
ActiveSupport.on_load(:action_controller) do
|
2010-09-27 18:42:02 +00:00
|
|
|
config.compile_methods! if config.respond_to?(:compile_methods!)
|
2010-09-27 12:50:39 +00:00
|
|
|
end
|
|
|
|
end
|
2017-07-10 15:12:45 +00:00
|
|
|
|
|
|
|
initializer "action_controller.request_forgery_protection" do |app|
|
|
|
|
ActiveSupport.on_load(:action_controller_base) do
|
|
|
|
if app.config.action_controller.default_protect_from_forgery
|
|
|
|
protect_from_forgery with: :exception
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-06-24 14:57:36 +00:00
|
|
|
|
|
|
|
initializer "action_controller.eager_load_actions" do
|
|
|
|
ActiveSupport.on_load(:after_initialize) do
|
|
|
|
ActionController::Metal.descendants.each(&:action_methods) if config.eager_load
|
|
|
|
end
|
|
|
|
end
|
2009-12-23 22:55:12 +00:00
|
|
|
end
|
2010-07-18 17:49:51 +00:00
|
|
|
end
|