Permalink
Browse files

Backport fix from master: fields_for with inline blocks and nested at…

…tributes already persisted does not render properly

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
spastorino committed Feb 8, 2011
1 parent 640b1f0 commit 4145810150070160677df00345fe22c66e457c1c
Showing with 6 additions and 9 deletions.
  1. +6 −9 actionpack/lib/action_view/helpers/form_helper.rb
@@ -541,7 +541,10 @@ def fields_for(record_or_name_or_array, *args, &block)
end
builder = options[:builder] || ActionView::Base.default_form_builder
@mtodd

mtodd Jun 19, 2011

Contributor

Was this line left in here accidentally?

@mtodd

mtodd Jun 19, 2011

Contributor

Heh, nevermind, misread line 544 and realized once I posted this comment. ❤️

- capture(builder.new(object_name, object, self, options, block), &block)
+ builder = builder.new(object_name, object, self, 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
@@ -1280,14 +1283,8 @@ def fields_for_with_nested_attributes(association_name, args, block)
def fields_for_nested_model(name, object, options, block)
object = object.to_model if object.respond_to?(:to_model)
- 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)

0 comments on commit 4145810

Please sign in to comment.