I'm using the restful_rails plugin and it has the following code
with_options(:controller => controller.to_s, :requirements => requirements) do |m|
m.connect "#{configuration[:prefix]}#{collection}/new", :action => 'new'
m.connect "#{configuration[:prefix]}#{collection}/:action", :action => 'collection'
configuration[:by].each do |attribute|
m.connect "#{configuration[:prefix]}#{collection}/:#{attribute}/:action", :action => "by_#{attribute}"
end
end
If this is run with the new routing code, then you get this error:
./script/server
=> Booting WEBrick...
./script/../config/../vendor/rails/actionpack/lib/action_controller/routing.rb:673:in `assign_route_options': action: requirements on a path segment must be regular expressions (TypeError)
It turns out that on the second m.connect, the requirements hash
has changed. If I put a puts requirements.inspect before and
after the first m.connect, then the hash has changed and it's clear
that it's the second :action => 'new' that is causing the error
in loading the application.
{:id=>/\w+/, :action=>/(?!\A(?:new|collection|by_(?-mix:id))\z)(?:[a-z](?:[-_]?[a-z])*)/, :controller=>/(?:[a-z](?:-?[a-z]+)*)/}
{:id=>/\w+/, :action=>"new", :controller=>"folder"}
This patch duplciates the hash for the :requirements, :defaults and
:conditions, and the options hash itself.
I duplicate options since the old routing code did:
class Route #:nodoc:
attr_accessor :components, :known
attr_reader :path, :options, :keys, :defaults
def initialize(path, options = {})
@path, @options = path, options
initialize_components path
defaults, conditions = initialize_hashes options.dup
Blair