Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add ActionController::Routing::Helpers, a module to contain common UR…

…L helpers such as polymorphic_url.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6722 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit a5fe13e871506e242071a6b0d0d96d1d9a78469a 1 parent a722b48
@seckar seckar authored
View
2  actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Add ActionController::Routing::Helpers, a module to contain common URL helpers such as polymorphic_url. [Nicholas Seckar]
+
* Included the HttpAuthentication plugin as part of core (ActionController::HttpAuthentication::Basic) [DHH]
* Modernize documentation for form helpers. [jeremymcanally]
View
2  actionpack/lib/action_controller/integration.rb
@@ -75,7 +75,7 @@ def reset!
unless defined? @named_routes_configured
# install the named routes in this session instance.
klass = class<<self; self; end
- Routing::Routes.named_routes.install(klass)
+ Routing::Routes.install_helpers(klass)
# the helpers are made protected by default--we make them public for
# easier access during testing and troubleshooting.
View
19 actionpack/lib/action_controller/routing.rb
@@ -252,7 +252,11 @@ module Routing
# The root paths which may contain controller files
mattr_accessor :controller_paths
self.controller_paths = []
-
+
+ # A helper module to hold URL related helpers.
+ module Helpers
+ end
+
class << self
def with_controllers(names)
prior_controllers = @possible_controllers
@@ -1134,15 +1138,20 @@ def builder
def draw
clear!
yield Mapper.new(self)
- named_routes.install
+ install_helpers
end
-
+
def clear!
routes.clear
named_routes.clear
@combined_regexp = nil
@routes_by_controller = nil
end
+
+ def install_helpers(destinations = [ActionController::Base, ActionView::Base])
+ Array(destinations).each { |d| d.send :include, Helpers }
+ named_routes.install(destinations)
+ end
def empty?
routes.empty?
@@ -1152,11 +1161,11 @@ def load!
Routing.use_controllers! nil # Clear the controller cache so we may discover new ones
clear!
load_routes!
- named_routes.install
+ install_helpers
end
alias reload load!
-
+
def load_routes!
if defined?(RAILS_ROOT) && defined?(::ActionController::Routing::Routes) && self == ::ActionController::Routing::Routes
load File.join("#{RAILS_ROOT}/config/routes.rb")
View
2  actionpack/lib/action_controller/url_rewriter.rb
@@ -21,7 +21,7 @@ module UrlWriter
self.default_url_options = {}
def self.included(base) #:nodoc:
- ActionController::Routing::Routes.named_routes.install base
+ ActionController::Routing::Routes.install_helpers base
base.mattr_accessor :default_url_options
base.default_url_options ||= default_url_options
end
View
2  actionpack/test/controller/action_pack_assertions_test.rb
@@ -209,7 +209,7 @@ def test_assert_redirect_to_named_route
map.route_one 'route_one', :controller => 'action_pack_assertions', :action => 'nothing'
map.connect ':controller/:action/:id'
end
- set.named_routes.install
+ set.install_helpers
process :redirect_to_named_route
assert_redirected_to 'http://test.host/route_one'
View
14 actionpack/test/controller/routing_test.rb
@@ -207,7 +207,7 @@ def test_named_route_with_nested_controller
def setup_for_named_route
x = Class.new
x.send(:define_method, :url_for) {|x| x}
- rs.named_routes.install(x)
+ rs.install_helpers(x)
x
end
@@ -1417,7 +1417,7 @@ def setup_named_route_test
end
klass = Class.new(MockController)
- set.named_routes.install(klass)
+ set.install_helpers(klass)
klass.new(set)
end
@@ -1885,4 +1885,14 @@ def test_normalize_windows_paths
assert_equal %w(vendor\\rails\\railties\\builtin\\rails_info vendor\\rails\\actionpack\\lib app\\controllers app\\helpers app\\models lib .), paths
end
+ def test_routing_helper_module
+ assert_kind_of Module, ActionController::Routing::Helpers
+
+ h = ActionController::Routing::Helpers
+ c = Class.new
+ assert ! c.ancestors.include?(h)
+ ActionController::Routing::Routes.install_helpers c
+ assert c.ancestors.include?(h)
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.