diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-12-02 01:10:50 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-12-02 01:10:50 +0000 |
commit | 84ca7e6ef7dd93dc9d224fc04ae174af4b3b8e64 (patch) | |
tree | fd4047de197abe9b88cb121500d8dcf6c3bceb44 /actionpack/lib | |
parent | d0ce7cd4c7eb24c4ade6d8fb4ec73576b8bc1977 (diff) | |
download | rails-84ca7e6ef7dd93dc9d224fc04ae174af4b3b8e64.tar.gz rails-84ca7e6ef7dd93dc9d224fc04ae174af4b3b8e64.tar.bz2 rails-84ca7e6ef7dd93dc9d224fc04ae174af4b3b8e64.zip |
Deal with nested fields_for too [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8253 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 16 |
1 files changed, 14 insertions, 2 deletions
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 |