Permalink
Browse files

Refactor the logic that checks whether or not to emit the hidden id f…

…ield

By checking for object.persisted? first, we avoid the hash lookups for
new objects.
  • Loading branch information...
1 parent e56e3db commit 7843e009d2bc8d088437ff6f43e47ba113de9dee @carlosantoniodasilva carlosantoniodasilva committed Jan 3, 2013
Showing with 6 additions and 7 deletions.
  1. +6 −7 actionpack/lib/action_view/helpers/form_helper.rb
@@ -1818,16 +1818,15 @@ def fields_for_with_nested_attributes(association_name, association, options, bl
end
end
- def fields_for_nested_model(name, object, options, block)
+ def fields_for_nested_model(name, object, fields_options, block)
object = convert_to_model(object)
+ emit_hidden_id = object.persisted? && fields_options.fetch(:include_id) {
+ options.fetch(:include_id, true)
+ }
- parent_include_id = self.options.fetch(:include_id, true)
- include_id = options.fetch(:include_id, parent_include_id)
- hidden_field_id = object.persisted? && include_id
-
- @template.fields_for(name, object, options) do |f|
+ @template.fields_for(name, object, fields_options) do |f|
output = @template.capture(f, &block)
- output.concat f.hidden_field(:id) if output && hidden_field_id && !f.emitted_hidden_id?
+ output.concat f.hidden_field(:id) if output && emit_hidden_id && !f.emitted_hidden_id?
output
end
end

0 comments on commit 7843e00

Please sign in to comment.