From 2d73a73d2f678945d57d95eae678d641ca9ea940 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 1 May 2014 11:18:20 -0700 Subject: extract route key translation to a method and reuse it --- .../action_dispatch/routing/polymorphic_routes.rb | 31 ++++++++++------------ 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'actionpack/lib/action_dispatch/routing') 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("_") -- cgit v1.2.3