railtie.rb 2.9 KB
Newer Older
1
require "rails"
2
require "action_controller"
3
require "action_view/railtie"
4
require "active_support/core_ext/class/subclasses"
5
require "active_support/deprecation/proxy_wrappers"
6
require "active_support/deprecation"
7

8
module ActionController
C
Carl Lerche 已提交
9
  class Railtie < Rails::Railtie
10
    railtie_name :action_controller
11

12
    require "action_controller/railties/log_subscriber"
13 14
    require "action_controller/railties/url_helpers"

15 16 17 18 19 20
    ad = config.action_dispatch
    config.action_controller.singleton_class.send(:define_method, :session) do
      ActiveSupport::Deprecation.warn "config.action_controller.session has been " \
        "renamed to config.action_dispatch.session.", caller
      ad.session
    end
21

22 23 24 25 26
    config.action_controller.singleton_class.send(:define_method, :session=) do |val|
      ActiveSupport::Deprecation.warn "config.action_controller.session has been " \
        "renamed to config.action_dispatch.session.", caller
      ad.session = val
    end
27

28 29 30 31
    config.action_controller.singleton_class.send(:define_method, :session_store) do
      ActiveSupport::Deprecation.warn "config.action_controller.session_store has been " \
        "renamed to config.action_dispatch.session_store.", caller
      ad.session_store
32 33
    end

34 35 36 37 38
    config.action_controller.singleton_class.send(:define_method, :session_store=) do |val|
      ActiveSupport::Deprecation.warn "config.action_controller.session_store has been " \
        "renamed to config.action_dispatch.session_store.", caller
      ad.session_store = val
    end
39

40 41 42
    log_subscriber ActionController::Railties::LogSubscriber.new

    initializer "action_controller.logger" do
43
      ActionController.base_hook { self.logger ||= Rails.logger }
44
    end
45

46
    initializer "action_controller.set_configs" do |app|
47 48
      paths = app.config.paths
      ac = app.config.action_controller
49 50

      ac.assets_dir      = paths.public.to_a.first
51 52
      ac.javascripts_dir = paths.public.javascripts.to_a.first
      ac.stylesheets_dir = paths.public.stylesheets.to_a.first
53
      ac.secret          = app.config.cookie_secret
54

C
Carlhuda 已提交
55 56 57
      ActionController.base_hook do
        self.config.merge!(ac)
      end
58 59
    end

60
    initializer "action_controller.initialize_framework_caches" do
61
      ActionController.base_hook { self.cache_store ||= RAILS_CACHE }
62
    end
63 64

    initializer "action_controller.set_helpers_path" do |app|
65 66 67
      ActionController.base_hook do
        self.helpers_path = app.config.paths.app.helpers.to_a
      end
68
    end
69 70

    initializer "action_controller.url_helpers" do |app|
71 72 73
      ActionController.base_hook do
        extend ::ActionController::Railtie::UrlHelpers.with(app.routes)
      end
74 75 76 77 78 79

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

      proxy = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(app.routes, message)
      ActionController::Routing::Routes = proxy
80
    end
81
  end
82
end