diff options
author | Coraline Ada Ehmke + Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-05 17:23:10 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-12 15:54:43 -0700 |
commit | b89dcde82253089da5378272af2fd58c05ec57cd (patch) | |
tree | 5109343b808e56b7239a7ce46fc4c78a70904286 /actionpack | |
parent | 7b9964c2ad2945be417179bfd73e67a45a263664 (diff) | |
download | rails-b89dcde82253089da5378272af2fd58c05ec57cd.tar.gz rails-b89dcde82253089da5378272af2fd58c05ec57cd.tar.bz2 rails-b89dcde82253089da5378272af2fd58c05ec57cd.zip |
simplified route method name generation
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/polymorphic_routes.rb | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 9b76e7d7b5..7b97bf0157 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -135,57 +135,47 @@ module ActionDispatch record = record_list.pop - inflection = :singular + inflection = lambda { |name| name.singular_route_key } should_pop = true if record.try(:persisted?) should_pop = false elsif options[:action] == 'new' else - inflection = :plural + inflection = lambda { |name| name.route_key } end - 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 + args = [] route = record_list.map { |parent| - if parent.is_a?(Symbol) || parent.is_a?(String) + case parent + when Symbol, String parent.to_s + when Class + args << parent + parent.model_name.singular_route_key else - model_name_from_record_or_class(parent).singular_route_key + args << parent.to_model + parent.to_model.class.model_name.singular_route_key end } route << - if record.is_a?(Symbol) || record.is_a?(String) + case record + when Symbol, String record.to_s + when Class + args << record unless should_pop + inflection.call record.model_name 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 + args << record.to_model unless should_pop + inflection.call record.to_model.class.model_name 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) } - recipient.send(named_route, *args, opts) end |