Permalink
Browse files

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
  • Loading branch information...
1 parent 783527f commit 719f1d68e4945332f71dc8ad93141780e60929b5 @timsly timsly committed Oct 24, 2013
Showing with 11 additions and 1 deletion.
  1. +5 −1 actionpack/lib/action_controller/metal/helpers.rb
  2. +6 −0 actionpack/test/controller/helper_test.rb
@@ -73,7 +73,11 @@ def helper_attr(*attrs)
# 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
@@ -201,6 +201,12 @@ def test_helper_proxy
# 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

0 comments on commit 719f1d6

Please sign in to comment.