aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-05-01 11:18:20 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-05-12 14:23:03 -0700
commit2d73a73d2f678945d57d95eae678d641ca9ea940 (patch)
tree19bd3d995bbb005219b633ce721e214fc2f52715 /actionpack/lib/action_dispatch/routing
parentffa53ffd4395cb9dc414f0d01cff27e9d18dd8f3 (diff)
downloadrails-2d73a73d2f678945d57d95eae678d641ca9ea940.tar.gz
rails-2d73a73d2f678945d57d95eae678d641ca9ea940.tar.bz2
rails-2d73a73d2f678945d57d95eae678d641ca9ea940.zip
extract route key translation to a method and reuse it
Diffstat (limited to 'actionpack/lib/action_dispatch/routing')
-rw-r--r--actionpack/lib/action_dispatch/routing/polymorphic_routes.rb31
1 files changed, 14 insertions, 17 deletions
diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
index b800ee6448..6afd745fe2 100644
--- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
+++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
@@ -178,32 +178,29 @@ module ActionDispatch
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("_")