aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-12-16 10:29:45 +0100
committerJosé Valim <jose.valim@gmail.com>2011-12-16 10:45:59 +0100
commit192e55c38ed9b48672b9e216c9805b782b835d78 (patch)
tree605ac731ca968efefcea18eec1b350574a170075 /actionpack/lib/action_dispatch/routing
parent5359262695b491422b18c565567e16ad50f6155e (diff)
downloadrails-192e55c38ed9b48672b9e216c9805b782b835d78.tar.gz
rails-192e55c38ed9b48672b9e216c9805b782b835d78.tar.bz2
rails-192e55c38ed9b48672b9e216c9805b782b835d78.zip
Do not raise an exception if an invalid route was generated automatically.
Diffstat (limited to 'actionpack/lib/action_dispatch/routing')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 88e422c05d..4d83c6dee1 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1286,7 +1286,7 @@ module ActionDispatch
action = nil
end
- if !options.fetch(:as) { true }
+ if !options.fetch(:as, true)
options.delete(:as)
else
options[:as] = name_for_action(options[:as], action)
@@ -1472,8 +1472,16 @@ module ActionDispatch
[name_prefix, member_name, prefix]
end
- candidate = name.select(&:present?).join("_").presence
- candidate unless as.nil? && @set.routes.find { |r| r.name == candidate }
+ if candidate = name.select(&:present?).join("_").presence
+ # If a name was not explicitly given, we check if it is valid
+ # and return nil in case it isn't. Otherwise, we pass the invalid name
+ # forward so the underlying router engine treats it and raises an exception.
+ if as.nil?
+ candidate unless @set.routes.find { |r| r.name == candidate } || candidate !~ /\A[_a-z]/i
+ else
+ candidate
+ end
+ end
end
end