Skip to content
Browse files

push list handling to the builder object

  • Loading branch information...
1 parent 3095f5b commit cc1ff82df47fe46b2a53af421c71f3189b8738a5 @tenderlove tenderlove committed
Showing with 30 additions and 30 deletions.
  1. +30 −30 actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
View
60 actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
@@ -125,10 +125,9 @@ def polymorphic_url(record_or_hash_or_array, options = {})
recipient = record_or_hash_or_array.shift
end
- method, args = handle_list record_or_hash_or_array,
- prefix,
- suffix,
- inflection
+ method, args = builder.handle_list record_or_hash_or_array,
+ prefix,
+ suffix
when Hash
unless record_or_hash_or_array[:id]
raise ArgumentError, "Nil location provided. Can't build URI."
@@ -227,51 +226,52 @@ def handle_model(record, prefix, suffix)
[named_route, args]
end
- end
-
- ROUTE_KEY = lambda { |name| name.route_key }
- SINGULAR_ROUTE_KEY = lambda { |name| name.singular_route_key }
- def handle_list(list, prefix, suffix, inflection)
- record_list = list.dup
- record = record_list.pop
+ def handle_list(list, prefix, suffix)
+ record_list = list.dup
+ record = record_list.pop
- args = []
+ args = []
- route = record_list.map { |parent|
- case parent
- when Symbol, String
- parent.to_s
- when Class
- args << parent
- parent.model_name.singular_route_key
- else
- args << parent.to_model
- parent.to_model.class.model_name.singular_route_key
- end
- }
+ route = record_list.map { |parent|
+ case parent
+ when Symbol, String
+ parent.to_s
+ when Class
+ args << parent
+ parent.model_name.singular_route_key
+ else
+ args << parent.to_model
+ parent.to_model.class.model_name.singular_route_key
+ end
+ }
- route <<
+ route <<
case record
when Symbol, String
record.to_s
when Class
- inflection.call record.model_name
+ @key_strategy.call record.model_name
else
if record.persisted?
args << record.to_model
record.to_model.class.model_name.singular_route_key
else
- inflection.call record.to_model.class.model_name
+ @key_strategy.call record.to_model.class.model_name
end
end
- route << suffix
+ route << suffix
- named_route = prefix + route.join("_")
- [named_route, args]
+ named_route = prefix + route.join("_")
+ [named_route, args]
+ end
end
+ ROUTE_KEY = lambda { |name| name.route_key }
+ SINGULAR_ROUTE_KEY = lambda { |name| name.singular_route_key }
+
+
def model_path_helper_call(record)
handle_model record, ''.freeze, "path".freeze, ROUTE_KEY
end

0 comments on commit cc1ff82

Please sign in to comment.
Something went wrong with that request. Please try again.