aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCoraline Ada Ehmke + Aaron Patterson <aaron.patterson@gmail.com>2014-05-05 16:51:01 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-05-12 15:54:43 -0700
commit1606fc9d840da869a60213bc889da6fcf1fdc431 (patch)
tree235309b9a8b80e9cfbda12c8b40752f3a287d06f
parente73740ffa7490072744a78c9d34461be867f0597 (diff)
downloadrails-1606fc9d840da869a60213bc889da6fcf1fdc431.tar.gz
rails-1606fc9d840da869a60213bc889da6fcf1fdc431.tar.bz2
rails-1606fc9d840da869a60213bc889da6fcf1fdc431.zip
pulling helpermethods up before refactoring
-rw-r--r--actionpack/lib/action_dispatch/routing/polymorphic_routes.rb66
1 files changed, 46 insertions, 20 deletions
diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
index c16924efff..0cc17f5cea 100644
--- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
+++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb
@@ -133,25 +133,60 @@ module ActionDispatch
end
- record = convert_to_model(record_list.pop)
- args.pop
+ record = record_list.pop
inflection = nil
- if options[:action] && options[:action].to_s == "new"
+ should_pop = true
+ if record.try(:persisted?)
+ should_pop = false
inflection = :singular
- elsif (record.respond_to?(:persisted?) && !record.persisted?)
- inflection = :plural
- elsif record.is_a?(Class)
- inflection = :plural
- else
- args << record
+ elsif options[:action] == 'new'
+ should_pop = true
inflection = :singular
+ else
+ should_pop = true
+ inflection = :plural
end
- args.delete_if {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}
+ record = record.respond_to?(:to_model) ? record.to_model : record
+
+ #if options[:action] && options[:action].to_s == "new"
+ # inflection = :singular
+ #elsif (record.respond_to?(:persisted?) && !record.persisted?)
+ # inflection = :plural
+ #elsif record.is_a?(Class)
+ # inflection = :plural
+ #else
+ # args << record
+ # inflection = :singular
+ #end
+
+ route = record_list.map { |parent|
+ if parent.is_a?(Symbol) || parent.is_a?(String)
+ parent.to_s
+ else
+ model_name_from_record_or_class(parent).singular_route_key
+ end
+ }
- named_route = build_named_route_call(record_list, record, inflection, options)
+ route <<
+ if record.is_a?(Symbol) || record.is_a?(String)
+ record.to_s
+ 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
+ end
+
+ route << routing_type(options)
+
+ named_route = action_prefix(options) + route.join("_")
+
+ args.pop if should_pop
+ args.delete_if {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}
args.collect! { |a| convert_to_model(a) }
@@ -200,15 +235,6 @@ module ActionDispatch
end
end
end
-
- def build_named_route_call(records, record, inflection, options)
- route = records.map { |parent| build_route_part parent, :singular }
-
- route << build_route_part(record, inflection)
- route << routing_type(options)
-
- action_prefix(options) + route.join("_")
- end
end
end
end