diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-09-26 01:51:41 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-09-26 01:51:41 -0300 |
commit | 5b648356019d9c263f40a1f2091b2e1bbb2114e9 (patch) | |
tree | 3907edac68183db718cfa60b7e1d5cc759e8d1bc /actionview/lib | |
parent | fa6807721297fb66917a8e1397791216ecba3b33 (diff) | |
parent | 7089768b700f79b2ae5171dc434ef45d16d18a63 (diff) | |
download | rails-5b648356019d9c263f40a1f2091b2e1bbb2114e9.tar.gz rails-5b648356019d9c263f40a1f2091b2e1bbb2114e9.tar.bz2 rails-5b648356019d9c263f40a1f2091b2e1bbb2114e9.zip |
Merge pull request #21431 from ojab/master
Handle nested fields_for by adding indexes to record_name
Diffstat (limited to 'actionview/lib')
-rw-r--r-- | actionview/lib/action_view/helpers/form_helper.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index 5a9a5d6d18..610f5c0b4a 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -1617,7 +1617,14 @@ module ActionView @auto_index end - record_name = index ? "#{object_name}[#{index}][#{record_name}]" : "#{object_name}[#{record_name}]" + record_name = if index + "#{object_name}[#{index}][#{record_name}]" + elsif record_name.to_s.end_with?('[]') + record_name = record_name.to_s.sub(/(.*)\[\]$/, "[\\1][#{record_object.id}]") + "#{object_name}#{record_name}" + else + "#{object_name}[#{record_name}]" + end fields_options[:child_index] = index @template.fields_for(record_name, record_object, fields_options, &block) |