Permalink
Browse files

extract route key translation to a method and reuse it

  • Loading branch information...
1 parent ffa53ff commit 2d73a73d2f678945d57d95eae678d641ca9ea940 @tenderlove tenderlove committed May 1, 2014
Showing with 14 additions and 17 deletions.
  1. +14 −17 actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
@@ -178,32 +178,29 @@ def routing_type(options)
options[:routing_type] || :url
end
- def build_named_route_call(records, record, inflection, options = {})
- if records.is_a?(Array)
- record = records.pop
- route = records.map do |parent|
- if parent.is_a?(Symbol) || parent.is_a?(String)
- parent
- else
- model_name_from_record_or_class(parent).singular_route_key
- end
- end
- else
- route = []
- end
-
+ def build_route_part(record, inflection)
if record.is_a?(Symbol) || record.is_a?(String)
- route << record
+ record.to_s
elsif record
if inflection == :singular
- route << model_name_from_record_or_class(record).singular_route_key
+ model_name_from_record_or_class(record).singular_route_key
else
- route << model_name_from_record_or_class(record).route_key
+ model_name_from_record_or_class(record).route_key
end
else
raise ArgumentError, "Nil location provided. Can't build URI."
end
+ end
+
+ def build_named_route_call(records, record, inflection, options)
+ if records.is_a?(Array)
+ record = records.pop
+ route = records.map { |parent| build_route_part parent, :singular }
+ else
+ route = []
+ end
+ route << build_route_part(record, inflection)
route << routing_type(options)
action_prefix(options) + route.join("_")

0 comments on commit 2d73a73

Please sign in to comment.