From 0523b55ab9f823b0cb3643714e890b2c2077820e Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 20 Sep 2010 00:10:16 -0700 Subject: file_field propagates up multipart property even inside of fields_for --- actionpack/lib/action_view/helpers/form_helper.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/action_view/helpers/form_helper.rb') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index ea59d328ea..6ca956f879 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -317,8 +317,8 @@ module ActionView options[:html] ||= {} options[:html][:remote] = options.delete(:remote) - builder = instantiate_builder(object_name, object, options, &proc) - fields_for = capture(builder, &proc) + builder = options[:parent_builder] = instantiate_builder(object_name, object, options, &proc) + fields_for = fields_for(object_name, object, options, &proc) default_options = builder.multipart? ? { :multipart => true } : {} output = form_tag(options.delete(:url) || {}, default_options.merge!(options.delete(:html) || {})) output << fields_for @@ -1119,9 +1119,14 @@ module ActionView attr_accessor :object_name, :object, :options - attr_reader :multipart + attr_reader :multipart, :parent_builder alias :multipart? :multipart + def multipart=(multipart) + @multipart = multipart + parent_builder.multipart = multipart if parent_builder + end + def self.model_name @model_name ||= Struct.new(:partial_path).new(name.demodulize.underscore.sub!(/_builder$/, '')) end @@ -1133,6 +1138,7 @@ module ActionView def initialize(object_name, object, template, options, proc) @nested_child_index = {} @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc + @parent_builder = options[:parent_builder] @default_options = @options ? @options.slice(:index) : {} if @object_name.to_s.match(/\[\]$/) if object ||= @template.instance_variable_get("@#{Regexp.last_match.pre_match}") and object.respond_to?(:to_param) @@ -1166,10 +1172,9 @@ module ActionView index = "" end - if options[:builder] - args << {} unless args.last.is_a?(Hash) - args.last[:builder] ||= options[:builder] - end + args << {} unless args.last.is_a?(Hash) + args.last[:builder] ||= options[:builder] + args.last[:parent_builder] = self case record_or_name_or_array when String, Symbol @@ -1209,7 +1214,7 @@ module ActionView end def file_field(method, options = {}) - @multipart = true + self.multipart = true @template.file_field(@object_name, method, objectify_options(options)) end # Add the submit button for the given form. When no value is given, it checks -- cgit v1.2.3