diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2011-02-08 18:02:16 -0200 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2011-02-08 18:04:12 -0200 |
commit | ee0b92ec7a87967c55fa2992350b12493d3c148b (patch) | |
tree | e5aa25224dec636728920c629ecea707853df833 /actionpack/lib | |
parent | 631e23ec6c1e482abcc242ae1d772a1831288465 (diff) | |
download | rails-ee0b92ec7a87967c55fa2992350b12493d3c148b.tar.gz rails-ee0b92ec7a87967c55fa2992350b12493d3c148b.tar.bz2 rails-ee0b92ec7a87967c55fa2992350b12493d3c148b.zip |
fields_for with inline blocks and nested attributes already persisted does not render properly
[#6381 state:committed]
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index d30fd248c1..befaa3e8d9 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -549,8 +549,11 @@ module ActionView # <% end %> # ... # <% end %> - def fields_for(record, record_object = nil, options = nil, &block) - capture(instantiate_builder(record, record_object, options, &block), &block) + def fields_for(record, record_object = nil, options = {}, &block) + builder = instantiate_builder(record, record_object, options, &block) + output = capture(builder, &block) + output.concat builder.hidden_field(:id) if output && options[:hidden_field_id] && !builder.emitted_hidden_id? + output end # Returns a label tag tailored for labelling an input field for a specified attribute (identified by +method+) on an object @@ -1323,14 +1326,8 @@ module ActionView def fields_for_nested_model(name, object, options, block) object = convert_to_model(object) - if object.persisted? - @template.fields_for(name, object, options) do |builder| - block.call(builder) - @template.concat builder.hidden_field(:id) unless builder.emitted_hidden_id? - end - else - @template.fields_for(name, object, options, &block) - end + options[:hidden_field_id] = object.persisted? + @template.fields_for(name, object, options, &block) end def nested_child_index(name) |