diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/application.rb | 14 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 12 | ||||
-rw-r--r-- | railties/lib/rails/engine.rb | 23 | ||||
-rw-r--r-- | railties/lib/rails/engine/configuration.rb | 2 |
4 files changed, 39 insertions, 12 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 300d4c6ab9..7c590b701e 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -124,16 +124,12 @@ module Rails alias :build_middleware_stack :app - def call(env) - env["action_dispatch.routes"] = routes - app.call(env.reverse_merge!(env_defaults)) - end - - def env_defaults - @env_defaults ||= { + def env_config + @env_config ||= super.merge({ "action_dispatch.parameter_filter" => config.filter_parameters, - "action_dispatch.secret_token" => config.secret_token - } + "action_dispatch.secret_token" => config.secret_token, + "action_dispatch.asset_path" => nil + }) end def initializers diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 7e34a16487..29fa9d14eb 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -25,6 +25,18 @@ module Rails @middleware = app_middleware end + def asset_path=(value) + action_mailer.asset_path = value if respond_to?(:action_mailer) && action_mailer + action_controller.asset_path = value if respond_to?(:action_controller) && action_controller + super(value) + end + + def asset_host=(value) + action_mailer.asset_host = value if action_mailer + action_controller.asset_host = value if action_controller + super(value) + end + def encoding=(value) @encoding = value if "ruby".encoding_aware? diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index d4a654fd08..6b1e21a798 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -147,6 +147,19 @@ module Rails # # Now, Engine will get only requests that were not handled by application. # + # == Asset path + # + # When you use engine with its own public directory, you will probably want to copy or symlink it + # to application's public directory. To simplify generating paths for assets, you can set asset_path + # for an Engine: + # + # class MyEngine::Engine < Rails::Engine + # config.asset_path = "/my_engine/%s" + # end + # + # With such config, asset paths will be automatically modified inside Engine: + # image_path("foo.jpg") #=> "/my_engine/images/foo.jpg" + # class Engine < Railtie autoload :Configurable, "rails/engine/configurable" autoload :Configuration, "rails/engine/configuration" @@ -219,8 +232,14 @@ module Rails end def call(env) - env["action_dispatch.routes"] = routes - app.call(env) + app.call(env.merge!(env_config)) + end + + def env_config + @env_config ||= { + 'action_dispatch.routes' => routes, + 'action_dispatch.asset_path' => config.asset_path + } end def routes diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index bf3ad1f26b..4588c27277 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -5,7 +5,7 @@ module Rails class Configuration < ::Rails::Railtie::Configuration attr_reader :root attr_writer :eager_load_paths, :autoload_once_paths, :autoload_paths - attr_accessor :middleware, :plugins + attr_accessor :middleware, :plugins, :asset_path def initialize(root=nil) super() |