railtie.rb 2.6 KB
Newer Older
1
require "rails"
2
require "action_controller"
3
require "action_dispatch/railtie"
4
require "action_view/railtie"
5
require "active_support/deprecation/proxy_wrappers"
6
require "active_support/deprecation"
7

8 9
require "action_controller/railties/url_helpers"

10
module ActionController
C
Carl Lerche 已提交
11
  class Railtie < Rails::Railtie
12
    config.action_controller = ActiveSupport::OrderedOptions.new
13

14 15 16 17 18
    config.action_controller.singleton_class.tap do |d|
      d.send(:define_method, :session) do
        ActiveSupport::Deprecation.warn "config.action_controller.session has been deprecated. " <<
          "Please use Rails.application.config.session_store instead.", caller
      end
19

20 21 22 23
      d.send(:define_method, :session=) do |val|
        ActiveSupport::Deprecation.warn "config.action_controller.session= has been deprecated. " <<
          "Please use config.session_store(name, options) instead.", caller
      end
24

25 26 27 28
      d.send(:define_method, :session_store) do
        ActiveSupport::Deprecation.warn "config.action_controller.session_store has been deprecated. " <<
          "Please use Rails.application.config.session_store instead.", caller
      end
29

30 31 32 33
      d.send(:define_method, :session_store=) do |val|
        ActiveSupport::Deprecation.warn "config.action_controller.session_store= has been deprecated. " <<
          "Please use config.session_store(name, options) instead.", caller
      end
34
    end
35

36
    initializer "action_controller.set_configs" do |app|
37 38
      paths = app.config.paths
      ac = app.config.action_controller
39

40 41 42 43 44
      ac.assets_dir           ||= paths.public.to_a.first
      ac.javascripts_dir      ||= paths.public.javascripts.to_a.first
      ac.stylesheets_dir      ||= paths.public.stylesheets.to_a.first
      ac.page_cache_directory ||= paths.public.to_a.first
      ac.helpers_path         ||= paths.app.helpers.to_a
45

46
      ActiveSupport.on_load(:action_controller) do
C
Carlhuda 已提交
47 48
        self.config.merge!(ac)
      end
49 50
    end

51 52
    initializer "action_controller.logger" do
      ActiveSupport.on_load(:action_controller) { self.logger ||= Rails.logger }
53
    end
54

55 56
    initializer "action_controller.initialize_framework_caches" do
      ActiveSupport.on_load(:action_controller) { self.cache_store ||= RAILS_CACHE }
57
    end
58 59

    initializer "action_controller.url_helpers" do |app|
60
      ActiveSupport.on_load(:action_controller) do
61
        extend ::ActionController::Railties::UrlHelpers.with(app.routes)
62
      end
63 64 65 66 67 68

      message = "ActionController::Routing::Routes is deprecated. " \
                "Instead, use Rails.application.routes"

      proxy = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(app.routes, message)
      ActionController::Routing::Routes = proxy
69
    end
70
  end
71
end