Permalink
Browse files

pull nil checks up

  • Loading branch information...
1 parent 6eeb76f commit 8d572ad1baa9171253957f174bf88283f84018e8 @tenderlove tenderlove committed May 2, 2014
Showing with 5 additions and 3 deletions.
  1. +5 −3 actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
@@ -120,6 +120,10 @@ def polymorphic_url(record_or_hash_or_array, options = {})
record_list = extract_record_list(record_or_hash_or_array)
end
+ if record_list.empty? || record_list.any?(&:nil?)
+ raise ArgumentError, "Nil location provided. Can't build URI."
+ end
+
record = convert_to_model(record_list.pop)
inflection = if options[:action] && options[:action].to_s == "new"
@@ -182,14 +186,12 @@ def routing_type(options)
def build_route_part(record, inflection)
if record.is_a?(Symbol) || record.is_a?(String)
record.to_s
- elsif record
+ else
if inflection == :singular
model_name_from_record_or_class(record).singular_route_key
else
model_name_from_record_or_class(record).route_key
end
- else
- raise ArgumentError, "Nil location provided. Can't build URI."
end
end

0 comments on commit 8d572ad

Please sign in to comment.