2007-02-09 09:04:31 +01:00
|
|
|
require 'cgi'
|
2007-12-24 22:02:14 +01:00
|
|
|
require 'uri'
|
|
|
|
require 'action_controller/polymorphic_routes'
|
2008-05-18 06:22:34 +02:00
|
|
|
require 'action_controller/routing/optimisations'
|
|
|
|
require 'action_controller/routing/routing_ext'
|
|
|
|
require 'action_controller/routing/route'
|
|
|
|
require 'action_controller/routing/segments'
|
|
|
|
require 'action_controller/routing/builder'
|
|
|
|
require 'action_controller/routing/route_set'
|
|
|
|
require 'action_controller/routing/recognition_optimisation'
|
2007-02-09 09:04:31 +01:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
module ActionController
|
2007-12-24 22:02:14 +01:00
|
|
|
# == Routing
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
|
|
|
# The routing module provides URL rewriting in native Ruby. It's a way to
|
|
|
|
# redirect incoming requests to controllers and actions. This replaces
|
2007-12-24 22:02:14 +01:00
|
|
|
# mod_rewrite rules. Best of all, Rails' Routing works with any web server.
|
2008-05-18 06:22:34 +02:00
|
|
|
# Routes are defined in <tt>config/routes.rb</tt>.
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# Consider the following route, installed by Rails when you generate your
|
2007-02-09 09:04:31 +01:00
|
|
|
# application:
|
|
|
|
#
|
|
|
|
# map.connect ':controller/:action/:id'
|
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# This route states that it expects requests to consist of a
|
2008-05-18 06:22:34 +02:00
|
|
|
# <tt>:controller</tt> followed by an <tt>:action</tt> that in turn is fed
|
|
|
|
# some <tt>:id</tt>.
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# Suppose you get an incoming request for <tt>/blog/edit/22</tt>, you'll end up
|
2007-02-09 09:04:31 +01:00
|
|
|
# with:
|
|
|
|
#
|
|
|
|
# params = { :controller => 'blog',
|
2007-12-24 22:02:14 +01:00
|
|
|
# :action => 'edit',
|
2007-02-09 09:04:31 +01:00
|
|
|
# :id => '22'
|
|
|
|
# }
|
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# Think of creating routes as drawing a map for your requests. The map tells
|
2007-02-09 09:04:31 +01:00
|
|
|
# them where to go based on some predefined pattern:
|
|
|
|
#
|
2008-05-18 06:22:34 +02:00
|
|
|
# ActionController::Routing::Routes.draw do |map|
|
|
|
|
# Pattern 1 tells some request to go to one place
|
|
|
|
# Pattern 2 tell them to go to another
|
|
|
|
# ...
|
|
|
|
# end
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
|
|
|
# The following symbols are special:
|
|
|
|
#
|
|
|
|
# :controller maps to your controller name
|
|
|
|
# :action maps to an action with your controllers
|
2007-12-24 22:02:14 +01:00
|
|
|
#
|
2008-05-18 06:22:34 +02:00
|
|
|
# Other names simply map to a parameter as in the case of <tt>:id</tt>.
|
2007-12-24 22:02:14 +01:00
|
|
|
#
|
2007-02-09 09:04:31 +01:00
|
|
|
# == Route priority
|
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# Not all routes are created equally. Routes have priority defined by the
|
2008-05-18 06:22:34 +02:00
|
|
|
# order of appearance of the routes in the <tt>config/routes.rb</tt> file. The priority goes
|
2007-02-09 09:04:31 +01:00
|
|
|
# from top to bottom. The last route in that file is at the lowest priority
|
2007-12-24 22:02:14 +01:00
|
|
|
# and will be applied last. If no route matches, 404 is returned.
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# Within blocks, the empty pattern is at the highest priority.
|
2007-02-09 09:04:31 +01:00
|
|
|
# In practice this works out nicely:
|
|
|
|
#
|
2008-05-18 06:22:34 +02:00
|
|
|
# ActionController::Routing::Routes.draw do |map|
|
|
|
|
# map.with_options :controller => 'blog' do |blog|
|
|
|
|
# blog.show '', :action => 'list'
|
|
|
|
# end
|
|
|
|
# map.connect ':controller/:action/:view'
|
|
|
|
# end
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# In this case, invoking blog controller (with an URL like '/blog/')
|
2007-02-09 09:04:31 +01:00
|
|
|
# without parameters will activate the 'list' action by default.
|
|
|
|
#
|
|
|
|
# == Defaults routes and default parameters
|
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# Setting a default route is straightforward in Rails - you simply append a
|
|
|
|
# Hash at the end of your mapping to set any default parameters.
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
|
|
|
# Example:
|
2008-05-18 06:22:34 +02:00
|
|
|
#
|
|
|
|
# ActionController::Routing:Routes.draw do |map|
|
|
|
|
# map.connect ':controller/:action/:id', :controller => 'blog'
|
|
|
|
# end
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# This sets up +blog+ as the default controller if no other is specified.
|
2007-02-09 09:04:31 +01:00
|
|
|
# This means visiting '/' would invoke the blog controller.
|
|
|
|
#
|
2008-05-18 06:22:34 +02:00
|
|
|
# More formally, you can define defaults in a route with the <tt>:defaults</tt> key.
|
2007-12-24 22:02:14 +01:00
|
|
|
#
|
|
|
|
# map.connect ':controller/:action/:id', :action => 'show', :defaults => { :page => 'Dashboard' }
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2008-09-07 07:54:05 +02:00
|
|
|
# Note: The default routes, as provided by the Rails generator, make all actions in every
|
|
|
|
# controller accessible via GET requests. You should consider removing them or commenting
|
|
|
|
# them out if you're using named routes and resources.
|
|
|
|
#
|
2007-02-09 09:04:31 +01:00
|
|
|
# == Named routes
|
|
|
|
#
|
|
|
|
# Routes can be named with the syntax <tt>map.name_of_route options</tt>,
|
|
|
|
# allowing for easy reference within your source as +name_of_route_url+
|
|
|
|
# for the full URL and +name_of_route_path+ for the URI path.
|
|
|
|
#
|
|
|
|
# Example:
|
2008-05-18 06:22:34 +02:00
|
|
|
#
|
2007-02-09 09:04:31 +01:00
|
|
|
# # In routes.rb
|
|
|
|
# map.login 'login', :controller => 'accounts', :action => 'login'
|
|
|
|
#
|
|
|
|
# # With render, redirect_to, tests, etc.
|
|
|
|
# redirect_to login_url
|
|
|
|
#
|
|
|
|
# Arguments can be passed as well.
|
|
|
|
#
|
|
|
|
# redirect_to show_item_path(:id => 25)
|
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# Use <tt>map.root</tt> as a shorthand to name a route for the root path "".
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
|
|
|
# # In routes.rb
|
|
|
|
# map.root :controller => 'blogs'
|
|
|
|
#
|
|
|
|
# # would recognize http://www.example.com/ as
|
|
|
|
# params = { :controller => 'blogs', :action => 'index' }
|
|
|
|
#
|
|
|
|
# # and provide these named routes
|
|
|
|
# root_url # => 'http://www.example.com/'
|
|
|
|
# root_path # => ''
|
|
|
|
#
|
2008-05-18 06:22:34 +02:00
|
|
|
# You can also specify an already-defined named route in your <tt>map.root</tt> call:
|
|
|
|
#
|
|
|
|
# # In routes.rb
|
|
|
|
# map.new_session :controller => 'sessions', :action => 'new'
|
|
|
|
# map.root :new_session
|
|
|
|
#
|
2007-02-09 09:04:31 +01:00
|
|
|
# Note: when using +with_options+, the route is simply named after the
|
|
|
|
# method you call on the block parameter rather than map.
|
|
|
|
#
|
|
|
|
# # In routes.rb
|
|
|
|
# map.with_options :controller => 'blog' do |blog|
|
|
|
|
# blog.show '', :action => 'list'
|
|
|
|
# blog.delete 'delete/:id', :action => 'delete',
|
|
|
|
# blog.edit 'edit/:id', :action => 'edit'
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# # provides named routes for show, delete, and edit
|
2007-12-24 22:02:14 +01:00
|
|
|
# link_to @article.title, show_path(:id => @article.id)
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
|
|
|
# == Pretty URLs
|
|
|
|
#
|
|
|
|
# Routes can generate pretty URLs. For example:
|
|
|
|
#
|
2008-05-18 06:22:34 +02:00
|
|
|
# map.connect 'articles/:year/:month/:day',
|
|
|
|
# :controller => 'articles',
|
|
|
|
# :action => 'find_by_date',
|
|
|
|
# :year => /\d{4}/,
|
|
|
|
# :month => /\d{1,2}/,
|
|
|
|
# :day => /\d{1,2}/
|
2007-12-24 22:02:14 +01:00
|
|
|
#
|
2008-05-18 06:22:34 +02:00
|
|
|
# Using the route above, the URL "http://localhost:3000/articles/2005/11/06"
|
|
|
|
# maps to
|
|
|
|
#
|
|
|
|
# params = {:year => '2005', :month => '11', :day => '06'}
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
|
|
|
# == Regular Expressions and parameters
|
2007-12-24 22:02:14 +01:00
|
|
|
# You can specify a regular expression to define a format for a parameter.
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2008-05-18 06:22:34 +02:00
|
|
|
# map.geocode 'geocode/:postalcode', :controller => 'geocode',
|
|
|
|
# :action => 'show', :postalcode => /\d{5}(-\d{4})?/
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# or, more formally:
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# map.geocode 'geocode/:postalcode', :controller => 'geocode',
|
|
|
|
# :action => 'show', :requirements => { :postalcode => /\d{5}(-\d{4})?/ }
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2008-05-18 06:22:34 +02:00
|
|
|
# Formats can include the 'ignorecase' and 'extended syntax' regular
|
|
|
|
# expression modifiers:
|
|
|
|
#
|
|
|
|
# map.geocode 'geocode/:postalcode', :controller => 'geocode',
|
|
|
|
# :action => 'show', :postalcode => /hx\d\d\s\d[a-z]{2}/i
|
|
|
|
#
|
|
|
|
# map.geocode 'geocode/:postalcode', :controller => 'geocode',
|
|
|
|
# :action => 'show',:requirements => {
|
|
|
|
# :postalcode => /# Postcode format
|
|
|
|
# \d{5} #Prefix
|
|
|
|
# (-\d{4})? #Suffix
|
|
|
|
# /x
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# Using the multiline match modifier will raise an ArgumentError.
|
|
|
|
# Encoding regular expression modifiers are silently ignored. The
|
|
|
|
# match will always use the default encoding or ASCII.
|
|
|
|
#
|
2007-02-09 09:04:31 +01:00
|
|
|
# == Route globbing
|
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# Specifying <tt>*[string]</tt> as part of a rule like:
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2008-05-18 06:22:34 +02:00
|
|
|
# map.connect '*path' , :controller => 'blog' , :action => 'unrecognized?'
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# 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 <tt>params[:path]</tt> in
|
|
|
|
# this case.
|
|
|
|
#
|
|
|
|
# == Route conditions
|
|
|
|
#
|
|
|
|
# With conditions you can define restrictions on routes. Currently the only valid condition is <tt>:method</tt>.
|
|
|
|
#
|
|
|
|
# * <tt>:method</tt> - Allows you to specify which method can access the route. Possible values are <tt>:post</tt>,
|
2008-10-27 07:47:01 +01:00
|
|
|
# <tt>:get</tt>, <tt>:put</tt>, <tt>:delete</tt> and <tt>:any</tt>. The default value is <tt>:any</tt>,
|
2007-12-24 22:02:14 +01:00
|
|
|
# <tt>:any</tt> means that any method can access the route.
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
#
|
|
|
|
# map.connect 'post/:id', :controller => 'posts', :action => 'show',
|
|
|
|
# :conditions => { :method => :get }
|
|
|
|
# map.connect 'post/:id', :controller => 'posts', :action => 'create_comment',
|
|
|
|
# :conditions => { :method => :post }
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# Now, if you POST to <tt>/posts/:id</tt>, it will route to the <tt>create_comment</tt> action. A GET on the same
|
|
|
|
# URL will route to the <tt>show</tt> action.
|
2008-10-27 07:47:01 +01:00
|
|
|
#
|
2007-02-09 09:04:31 +01:00
|
|
|
# == Reloading routes
|
|
|
|
#
|
|
|
|
# You can reload routes if you feel you must:
|
|
|
|
#
|
2008-05-18 06:22:34 +02:00
|
|
|
# ActionController::Routing::Routes.reload
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# This will clear all named routes and reload routes.rb if the file has been modified from
|
2008-05-18 06:22:34 +02:00
|
|
|
# last load. To absolutely force reloading, use <tt>reload!</tt>.
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
|
|
|
# == Testing Routes
|
|
|
|
#
|
|
|
|
# The two main methods for testing your routes:
|
|
|
|
#
|
|
|
|
# === +assert_routing+
|
2007-12-24 22:02:14 +01:00
|
|
|
#
|
2008-05-18 06:22:34 +02:00
|
|
|
# def test_movie_route_properly_splits
|
|
|
|
# opts = {:controller => "plugin", :action => "checkout", :id => "2"}
|
|
|
|
# assert_routing "plugin/checkout/2", opts
|
|
|
|
# end
|
2007-12-24 22:02:14 +01:00
|
|
|
#
|
2007-02-09 09:04:31 +01:00
|
|
|
# +assert_routing+ lets you test whether or not the route properly resolves into options.
|
|
|
|
#
|
|
|
|
# === +assert_recognizes+
|
|
|
|
#
|
2008-05-18 06:22:34 +02:00
|
|
|
# def test_route_has_options
|
|
|
|
# opts = {:controller => "plugin", :action => "show", :id => "12"}
|
|
|
|
# assert_recognizes opts, "/plugins/show/12"
|
|
|
|
# end
|
2007-12-24 22:02:14 +01:00
|
|
|
#
|
2007-02-09 09:04:31 +01:00
|
|
|
# Note the subtle difference between the two: +assert_routing+ tests that
|
2007-12-24 22:02:14 +01:00
|
|
|
# a URL fits options while +assert_recognizes+ tests that a URL
|
2007-02-09 09:04:31 +01:00
|
|
|
# breaks into parameters properly.
|
|
|
|
#
|
|
|
|
# In tests you can simply pass the URL or named route to +get+ or +post+.
|
|
|
|
#
|
2008-05-18 06:22:34 +02:00
|
|
|
# def send_to_jail
|
|
|
|
# get '/jail'
|
|
|
|
# assert_response :success
|
|
|
|
# assert_template "jail/front"
|
|
|
|
# end
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2008-05-18 06:22:34 +02:00
|
|
|
# def goes_to_login
|
|
|
|
# get login_url
|
|
|
|
# #...
|
|
|
|
# end
|
2007-02-09 09:04:31 +01:00
|
|
|
#
|
2007-12-24 22:02:14 +01:00
|
|
|
# == View a list of all your routes
|
|
|
|
#
|
|
|
|
# Run <tt>rake routes</tt>.
|
|
|
|
#
|
2007-02-09 09:04:31 +01:00
|
|
|
module Routing
|
2007-12-24 22:02:14 +01:00
|
|
|
SEPARATORS = %w( / . ? )
|
|
|
|
|
|
|
|
HTTP_METHODS = [:get, :head, :post, :put, :delete]
|
|
|
|
|
|
|
|
ALLOWED_REQUIREMENTS_FOR_OPTIMISATION = [:controller, :action].to_set
|
2007-02-09 09:04:31 +01:00
|
|
|
|
|
|
|
# The root paths which may contain controller files
|
|
|
|
mattr_accessor :controller_paths
|
|
|
|
self.controller_paths = []
|
|
|
|
|
2007-12-24 22:02:14 +01:00
|
|
|
# A helper module to hold URL related helpers.
|
|
|
|
module Helpers
|
|
|
|
include PolymorphicRoutes
|
|
|
|
end
|
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
class << self
|
2008-10-27 07:47:01 +01:00
|
|
|
# Expects an array of controller names as the first argument.
|
|
|
|
# Executes the passed block with only the named controllers named available.
|
|
|
|
# This method is used in internal Rails testing.
|
2007-02-09 09:04:31 +01:00
|
|
|
def with_controllers(names)
|
|
|
|
prior_controllers = @possible_controllers
|
|
|
|
use_controllers! names
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
use_controllers! prior_controllers
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
|
2008-10-27 07:47:01 +01:00
|
|
|
# Returns an array of paths, cleaned of double-slashes and relative path references.
|
|
|
|
# * "\\\" and "//" become "\\" or "/".
|
|
|
|
# * "/foo/bar/../config" becomes "/foo/config".
|
|
|
|
# The returned array is sorted by length, descending.
|
2007-02-09 09:04:31 +01:00
|
|
|
def normalize_paths(paths)
|
|
|
|
# do the hokey-pokey of path normalization...
|
|
|
|
paths = paths.collect do |path|
|
|
|
|
path = path.
|
|
|
|
gsub("//", "/"). # replace double / chars with a single
|
|
|
|
gsub("\\\\", "\\"). # replace double \ chars with a single
|
|
|
|
gsub(%r{(.)[\\/]$}, '\1') # drop final / or \ if path ends with it
|
2007-01-22 14:43:50 +01:00
|
|
|
|
2007-02-09 09:04:31 +01:00
|
|
|
# eliminate .. paths where possible
|
2008-05-18 06:22:34 +02:00
|
|
|
re = %r{[^/\\]+[/\\]\.\.[/\\]}
|
|
|
|
path.gsub!(re, "") while path.match(re)
|
2007-02-09 09:04:31 +01:00
|
|
|
path
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
|
|
|
|
# start with longest path, first
|
|
|
|
paths = paths.uniq.sort_by { |path| - path.length }
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
|
2008-10-27 07:47:01 +01:00
|
|
|
# Returns the array of controller names currently available to ActionController::Routing.
|
2007-02-09 09:04:31 +01:00
|
|
|
def possible_controllers
|
|
|
|
unless @possible_controllers
|
|
|
|
@possible_controllers = []
|
2007-12-24 22:02:14 +01:00
|
|
|
|
2007-02-09 09:04:31 +01:00
|
|
|
paths = controller_paths.select { |path| File.directory?(path) && path != "." }
|
|
|
|
|
|
|
|
seen_paths = Hash.new {|h, k| h[k] = true; false}
|
|
|
|
normalize_paths(paths).each do |load_path|
|
|
|
|
Dir["#{load_path}/**/*_controller.rb"].collect do |path|
|
|
|
|
next if seen_paths[path.gsub(%r{^\.[/\\]}, "")]
|
2007-12-24 22:02:14 +01:00
|
|
|
|
2007-02-09 09:04:31 +01:00
|
|
|
controller_name = path[(load_path.length + 1)..-1]
|
2007-12-24 22:02:14 +01:00
|
|
|
|
2007-02-09 09:04:31 +01:00
|
|
|
controller_name.gsub!(/_controller\.rb\Z/, '')
|
|
|
|
@possible_controllers << controller_name
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# remove duplicates
|
|
|
|
@possible_controllers.uniq!
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
2007-02-09 09:04:31 +01:00
|
|
|
@possible_controllers
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
|
2008-10-27 07:47:01 +01:00
|
|
|
# Replaces the internal list of controllers available to ActionController::Routing with the passed argument.
|
|
|
|
# ActionController::Routing.use_controllers!([ "posts", "comments", "admin/comments" ])
|
2007-02-09 09:04:31 +01:00
|
|
|
def use_controllers!(controller_names)
|
|
|
|
@possible_controllers = controller_names
|
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
|
2008-10-27 07:47:01 +01:00
|
|
|
# Returns a controller path for a new +controller+ based on a +previous+ controller path.
|
|
|
|
# Handles 4 scenarios:
|
|
|
|
#
|
|
|
|
# * stay in the previous controller:
|
|
|
|
# controller_relative_to( nil, "groups/discussion" ) # => "groups/discussion"
|
|
|
|
#
|
|
|
|
# * stay in the previous namespace:
|
|
|
|
# controller_relative_to( "posts", "groups/discussion" ) # => "groups/posts"
|
|
|
|
#
|
|
|
|
# * forced move to the root namespace:
|
|
|
|
# controller_relative_to( "/posts", "groups/discussion" ) # => "posts"
|
|
|
|
#
|
|
|
|
# * previous namespace is root:
|
|
|
|
# controller_relative_to( "posts", "anything_with_no_slashes" ) # =>"posts"
|
|
|
|
#
|
2007-02-09 09:04:31 +01:00
|
|
|
def controller_relative_to(controller, previous)
|
|
|
|
if controller.nil? then previous
|
|
|
|
elsif controller[0] == ?/ then controller[1..-1]
|
|
|
|
elsif %r{^(.*)/} =~ previous then "#{$1}/#{controller}"
|
|
|
|
else controller
|
2007-12-24 22:02:14 +01:00
|
|
|
end
|
|
|
|
end
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
Routes = RouteSet.new
|
2007-12-24 22:02:14 +01:00
|
|
|
|
2008-09-07 07:54:05 +02:00
|
|
|
ActiveSupport::Inflector.module_eval do
|
2008-10-27 07:47:01 +01:00
|
|
|
# Ensures that routes are reloaded when Rails inflections are updated.
|
2007-12-24 22:02:14 +01:00
|
|
|
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
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
end
|