Install url helpers on module instance so they can be accessed
globally
This commit is contained in:
parent
b652aa8121
commit
13a783672a
@ -65,7 +65,7 @@ def split_glob_param!(params)
|
|||||||
# named routes.
|
# named routes.
|
||||||
class NamedRouteCollection #:nodoc:
|
class NamedRouteCollection #:nodoc:
|
||||||
include Enumerable
|
include Enumerable
|
||||||
attr_reader :routes, :helpers
|
attr_reader :routes, :helpers, :module
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
clear!
|
clear!
|
||||||
@ -241,21 +241,29 @@ def install_helpers(destinations = [ActionController::Base, ActionView::Base], r
|
|||||||
|
|
||||||
def url_helpers
|
def url_helpers
|
||||||
@url_helpers ||= begin
|
@url_helpers ||= begin
|
||||||
router = self
|
routes = self
|
||||||
|
|
||||||
Module.new do
|
helpers = Module.new do
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
include UrlFor
|
include UrlFor
|
||||||
|
|
||||||
|
@routes = routes
|
||||||
|
class << self
|
||||||
|
delegate :url_for, :to => '@routes'
|
||||||
|
end
|
||||||
|
extend routes.named_routes.module
|
||||||
|
|
||||||
# ROUTES TODO: install_helpers isn't great... can we make a module with the stuff that
|
# ROUTES TODO: install_helpers isn't great... can we make a module with the stuff that
|
||||||
# we can include?
|
# we can include?
|
||||||
# Yes plz - JP
|
# Yes plz - JP
|
||||||
included do
|
included do
|
||||||
router.install_helpers(self)
|
routes.install_helpers(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
define_method(:_router) { router }
|
define_method(:_router) { routes }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
helpers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -193,6 +193,7 @@ def test_login
|
|||||||
assert_equal '/login', url_for(:controller => 'sessions', :action => 'new', :only_path => true)
|
assert_equal '/login', url_for(:controller => 'sessions', :action => 'new', :only_path => true)
|
||||||
|
|
||||||
assert_equal 'http://rubyonrails.org/login', Routes.url_for(:controller => 'sessions', :action => 'create')
|
assert_equal 'http://rubyonrails.org/login', Routes.url_for(:controller => 'sessions', :action => 'create')
|
||||||
|
assert_equal 'http://rubyonrails.org/login', Routes.url_helpers.login_url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user