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