Permalink
Browse files

only do one nil check against the controller

  • Loading branch information...
tenderlove committed May 28, 2014
1 parent 8d30983 commit b27a3aff35bf2a7515d4236afe191a7c63481a23
Showing with 9 additions and 9 deletions.
  1. +9 −9 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -250,8 +250,14 @@ def default_controller_and_action
if controller.is_a? Regexp
hash[:controller] = controller
else
- check_controller! controller
- hash[:controller] = controller.to_s if controller
+ if controller
+ hash[:controller] = check_controller!(controller).to_s
+ else
+ unless segment_keys.include?(:controller)
+ message = "Missing :controller key on routes definition, please check your routes."
+ raise ArgumentError, message
+ end
+ end
end
if action.is_a? Regexp
@@ -292,13 +298,7 @@ def check_action!(action)
end
def check_controller!(controller)
- unless controller || segment_keys.include?(:controller)
- message = "Missing :controller key on routes definition, please check your routes."
- raise ArgumentError, message
- end
-
- return unless controller
- return if controller =~ /\A[a-z_0-9][a-z_0-9\/]*\z/
+ return controller if controller =~ /\A[a-z_0-9][a-z_0-9\/]*\z/
if controller =~ %r{\A/}
message = "controller name should not start with a slash"

0 comments on commit b27a3af

Please sign in to comment.