提交 719f1d68 编写于 作者: T Tima Maslyuchenko

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
上级 783527fd
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册