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.
This commit is contained in:
parent
04338b9e3b
commit
e56e3db6e6
@ -705,9 +705,7 @@ def apply_form_for_options!(record, object, options) #:nodoc:
|
||||
# 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
|
||||
@ -1825,8 +1823,13 @@ def fields_for_nested_model(name, object, options, block)
|
||||
|
||||
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)
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user