aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/form_helper.rb
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-01-03 01:11:10 -0200
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-01-06 10:54:22 -0200
commite56e3db6e6c3ed1618311122c51066a8ac8beb0e (patch)
tree32bdfbac4c0e194fdb3c2bb3ddba1525a116157a /actionpack/lib/action_view/helpers/form_helper.rb
parent04338b9e3b6babdc4b5938d4eaf41de620985c41 (diff)
downloadrails-e56e3db6e6c3ed1618311122c51066a8ac8beb0e.tar.gz
rails-e56e3db6e6c3ed1618311122c51066a8ac8beb0e.tar.bz2
rails-e56e3db6e6c3ed1618311122c51066a8ac8beb0e.zip
Move the hidden :id field logic to where it belongs to
When dealing with nested forms, Rails automatically generates a hidden field with the id value of the current object being generated by fields_for. This logic was inside the method that's available from the template object, but we just need it when really dealing with nested attributes, so moving the code to here makes more sense.
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb15
1 files changed, 9 insertions, 6 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 481ddcb981..d0c8edc901 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -705,9 +705,7 @@ module ActionView
# to prevent fields_for from rendering it automatically.
def fields_for(record_name, record_object = nil, options = {}, &block)
builder = instantiate_builder(record_name, record_object, options)
- output = capture(builder, &block)
- output.concat builder.hidden_field(:id) if output && options[:hidden_field_id] && !builder.emitted_hidden_id?
- output
+ capture(builder, &block)
end
# Returns a label tag tailored for labelling an input field for a specified attribute (identified by +method+) on an object
@@ -1824,9 +1822,14 @@ module ActionView
object = convert_to_model(object)
parent_include_id = self.options.fetch(:include_id, true)
- include_id = options.fetch(:include_id, parent_include_id)
- options[:hidden_field_id] = object.persisted? && include_id
- @template.fields_for(name, object, options, &block)
+ include_id = options.fetch(:include_id, parent_include_id)
+ hidden_field_id = object.persisted? && include_id
+
+ @template.fields_for(name, object, options) do |f|
+ output = @template.capture(f, &block)
+ output.concat f.hidden_field(:id) if output && hidden_field_id && !f.emitted_hidden_id?
+ output
+ end
end
def nested_child_index(name)