Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

extract controller checks to methods

  • Loading branch information...
commit ddda5e70f79288f03a873cc8b4dbc6c086f4ad82 1 parent 1ad50aa
@tenderlove tenderlove authored
Showing with 26 additions and 19 deletions.
  1. +26 −19 actionpack/lib/action_dispatch/routing/mapper.rb
View
45 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -260,28 +260,11 @@ def default_controller_and_action
end
end
- if controller.is_a?(String) && controller =~ %r{\A/}
- raise ArgumentError, "controller name should not start with a slash"
- end
-
controller = controller.to_s unless controller.is_a?(Regexp)
action = action.to_s unless action.is_a?(Regexp)
- if controller.blank? && segment_keys.exclude?(:controller)
- message = "Missing :controller key on routes definition, please check your routes."
- raise ArgumentError, message
- end
-
- if action.blank? && segment_keys.exclude?(:action)
- message = "Missing :action key on routes definition, please check your routes."
- raise ArgumentError, message
- end
-
- if controller.is_a?(String) && controller !~ /\A[a-z_0-9\/]*\z/
- message = "'#{controller}' is not a supported controller name. This can lead to potential routing problems."
- message << " See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use"
- raise ArgumentError, message
- end
+ check_action! action
+ check_controller! controller
hash = {}
hash[:controller] = controller unless controller.blank?
@@ -290,6 +273,30 @@ def default_controller_and_action
end
end
+ def check_action!(action)
+ if action.blank? && segment_keys.exclude?(:action)
+ message = "Missing :action key on routes definition, please check your routes."
+ raise ArgumentError, message
+ end
+ end
+
+ def check_controller!(controller)
+ if controller.is_a?(String) && controller =~ %r{\A/}
+ raise ArgumentError, "controller name should not start with a slash"
+ end
+
+ if controller.blank? && segment_keys.exclude?(:controller)
+ message = "Missing :controller key on routes definition, please check your routes."
+ raise ArgumentError, message
+ end
+
+ if controller.is_a?(String) && controller !~ /\A[a-z_0-9\/]*\z/
+ message = "'#{controller}' is not a supported controller name. This can lead to potential routing problems."
+ message << " See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use"
+ raise ArgumentError, message
+ end
+ end
+
def blocks
if options[:constraints].present? && !options[:constraints].is_a?(Hash)
[options[:constraints]]
Please sign in to comment.
Something went wrong with that request. Please try again.