From a5fe13e871506e242071a6b0d0d96d1d9a78469a Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Sat, 12 May 2007 04:18:46 +0000 Subject: Add ActionController::Routing::Helpers, a module to contain common URL helpers such as polymorphic_url. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6722 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/routing.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_controller/routing.rb') diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 1710ffcee9..9bbb51cfbf 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -252,7 +252,11 @@ module ActionController # 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 @@ module ActionController 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 @@ module ActionController 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") -- cgit v1.2.3