提交 ddda5e70 编写于 作者: A Aaron Patterson

extract controller checks to methods

上级 1ad50aa3
......@@ -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]]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册