提交 4ba24ba0 编写于 作者: A Andrew White

Allow generated url helpers to be overriden [#5243 state:resolved]

上级 c40074c1
......@@ -46,14 +46,14 @@ def view_context_class
@view_context_class ||= begin
controller = self
Class.new(ActionView::Base) do
if controller.respond_to?(:_routes) && controller._routes
include controller._routes.url_helpers
include controller._routes.mounted_helpers
end
if controller.respond_to?(:_helpers)
include controller._helpers
if controller.respond_to?(:_routes) && controller._routes
include controller._routes.url_helpers
include controller._routes.mounted_helpers
end
# TODO: Fix RJS to not require this
self.helpers = controller._helpers
end
......
......@@ -433,6 +433,10 @@ class UrlHelperController < ActionController::Base
match 'url_helper_controller_test/url_helper/normalize_recall_params',
:to => UrlHelperController.action(:normalize_recall),
:as => :normalize_recall_params
match '/url_helper_controller_test/url_helper/override_url_helper/default',
:to => 'url_helper_controller_test/url_helper#override_url_helper',
:as => :override_url_helper
end
def show
......@@ -468,6 +472,15 @@ def recall_params_not_changed
end
def rescue_action(e) raise e end
def override_url_helper
render :inline => '<%= override_url_helper_path %>'
end
def override_url_helper_path
'/url_helper_controller_test/url_helper/override_url_helper/override'
end
helper_method :override_url_helper_path
end
tests UrlHelperController
......@@ -527,6 +540,11 @@ def test_recall_params_should_normalize_id
get :show, :name => '123'
assert_equal 'ok', @response.body
end
def test_url_helper_can_be_overriden
get :override_url_helper
assert_equal '/url_helper_controller_test/url_helper/override_url_helper/override', @response.body
end
end
class TasksController < ActionController::Base
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册