From 84ca7e6ef7dd93dc9d224fc04ae174af4b3b8e64 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 2 Dec 2007 01:10:50 +0000 Subject: Deal with nested fields_for too [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8253 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/form_helper.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_view/helpers/form_helper.rb') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 4c050cae00..2bfb896633 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -639,8 +639,20 @@ module ActionView class_eval src, __FILE__, __LINE__ end - def fields_for(name, *args, &block) - name = "#{object_name}[#{name}]" + def fields_for(record_or_name_or_array, *args, &block) + case record_or_name_or_array + when String, Symbol + name = "#{object_name}[#{record_or_name_or_array}]" + when Array + object = record_or_name_or_array.last + name = "#{object_name}[#{ActionController::RecordIdentifier.singular_class_name(object)}]" + args.unshift(object) + else + object = record_or_name_or_array + name = "#{object_name}[#{ActionController::RecordIdentifier.singular_class_name(object)}]" + args.unshift(object) + end + @template.fields_for(name, *args, &block) end -- cgit v1.2.3