diff options
author | Tima Maslyuchenko <insside@gmail.com> | 2013-10-24 07:54:20 +0300 |
---|---|---|
committer | Tima Maslyuchenko <insside@gmail.com> | 2013-10-24 08:03:31 +0300 |
commit | 719f1d68e4945332f71dc8ad93141780e60929b5 (patch) | |
tree | 48e03cefab7b9bc5d2a95b322caf6dd59757baac | |
parent | 783527fd877c491cf5f2f563ee42d5bc19e1b78b (diff) | |
download | rails-719f1d68e4945332f71dc8ad93141780e60929b5.tar.gz rails-719f1d68e4945332f71dc8ad93141780e60929b5.tar.bz2 rails-719f1d68e4945332f71dc8ad93141780e60929b5.zip |
pass app config to controller helper proxy
After this fix application config become available when calling helper outisde of view
config/application.rb
#...
config.asset_host = 'http://mycdn.com'
#...
Somewhere else
ActionController::Base.helpers.asset_path('fallback.png')
# => http://mycdn.com/assets/fallback.png
-rw-r--r-- | actionpack/lib/action_controller/metal/helpers.rb | 6 | ||||
-rw-r--r-- | actionpack/test/controller/helper_test.rb | 6 |
2 files changed, 11 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/metal/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb index b53ae7f29f..a9c3e438fb 100644 --- a/actionpack/lib/action_controller/metal/helpers.rb +++ b/actionpack/lib/action_controller/metal/helpers.rb @@ -73,7 +73,11 @@ module ActionController # Provides a proxy to access helpers methods from outside the view. def helpers - @helper_proxy ||= ActionView::Base.new.extend(_helpers) + @helper_proxy ||= begin + proxy = ActionView::Base.new + proxy.config = config.inheritable_copy + proxy.extend(_helpers) + end end # Overwrite modules_for_helpers to accept :all as argument, which loads diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index 248c81193e..20f99f19ee 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -201,6 +201,12 @@ class HelperTest < ActiveSupport::TestCase # fun/pdf_helper.rb assert methods.include?(:foobar) end + + def test_helper_proxy_config + AllHelpersController.config.my_var = 'smth' + + assert_equal 'smth', AllHelpersController.helpers.config.my_var + end private def expected_helper_methods |