From bd03bf9f5e2a1a8a667785e82658e3efa3f08a25 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Sat, 13 Oct 2007 03:28:35 +0000 Subject: Make sure that custom inflections are picked up by map.resources by triggering a routing reload when new inflections are defined. Closes #9815 [mislav, kampers] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7849 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/routing.rb | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 3a4d2aafe3..78b1759e3f 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -196,11 +196,13 @@ module ActionController # # == Route globbing # - # Specifying *[string] as part of a rule like : + # Specifying *[string] as part of a rule like: # # map.connect '*path' , :controller => 'blog' , :action => 'unrecognized?' # - # will glob all remaining parts of the route that were not recognized earlier. This idiom must appear at the end of the path. The globbed values are in params[:path] in this case. + # will glob all remaining parts of the route that were not recognized earlier. This idiom + # must appear at the end of the path. The globbed values are in params[:path] in + # this case. # # == Reloading routes # @@ -208,7 +210,8 @@ module ActionController # # ActionController::Routing::Routes.reload # - # This will clear all named routes and reload routes.rb + # This will clear all named routes and reload routes.rb if the file has been modified from + # last load. To absolutely force reloading, use +reload!+. # # == Testing Routes # @@ -1248,12 +1251,12 @@ module ActionController alias reload! load! def reload - if @routes_last_modified - mtime=File.stat("#{RAILS_ROOT}/config/routes.rb").mtime + if @routes_last_modified && defined?(RAILS_ROOT) + mtime = File.stat("#{RAILS_ROOT}/config/routes.rb").mtime # if it hasn't been changed, then just return return if mtime == @routes_last_modified # if it has changed then record the new time and fall to the load! below - @routes_last_modified=mtime + @routes_last_modified = mtime end load! end @@ -1261,7 +1264,7 @@ module ActionController def load_routes! if defined?(RAILS_ROOT) && defined?(::ActionController::Routing::Routes) && self == ::ActionController::Routing::Routes load File.join("#{RAILS_ROOT}/config/routes.rb") - @routes_last_modified=File.stat("#{RAILS_ROOT}/config/routes.rb").mtime + @routes_last_modified = File.stat("#{RAILS_ROOT}/config/routes.rb").mtime else add_route ":controller/:action/:id" end @@ -1455,5 +1458,15 @@ module ActionController end Routes = RouteSet.new + + ::Inflector.module_eval do + def inflections_with_route_reloading(&block) + returning(inflections_without_route_reloading(&block)) { + ActionController::Routing::Routes.reload! if block_given? + } + end + + alias_method_chain :inflections, :route_reloading + end end end -- cgit v1.2.3