John Merlino
2012-Mar-21 21:12 UTC
rails source fields_for has an options hash not defined anywhere
Hey all, I looked at source code for fields_for: def fields_for(record_name, record_object = nil, fields_options = {}, &block) fields_options, record_object = record_object, nil if record_object.is_a?(Hash) && record_object.extractable_options? fields_options[:builder] ||= options[:builder] fields_options[:parent_builder] = self fields_options[:namespace] fields_options[:parent_builder].options[:namespace] case record_name when String, Symbol if nested_attributes_association?(record_name) return fields_for_with_nested_attributes(record_name, record_object, fields_options, block) end else record_object = record_name.is_a?(Array) ? record_name.last : record_name record_name = ActiveModel::Naming.param_key(record_object) end index = if options.has_key?(:index) "[#{options[:index]}]" elsif defined?(@auto_index) self.object_name = @object_name.to_s.sub(%r\[\]$/,"") "[#{@auto_index}]" end record_name = "#{object_name}#{index}[#{record_name}]" @template.fields_for(record_name, record_object, fields_options, &block) end Notice this part: options[:builder] this options hash is no where to be defined. In argument list, there''s only a fields_options hash. Reason why this matters to me is because I am trying to override this method in my application_helper.rb in order to extend it. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
eggie5
2013-Apr-03 05:21 UTC
Re: rails source fields_for has an options hash not defined anywhere
I want to know this too. Did you find out? On Wednesday, March 21, 2012 2:12:09 PM UTC-7, John Merlino wrote:> > Hey all, > > I looked at source code for fields_for: > > def fields_for(record_name, record_object = nil, fields_options = {}, > &block) > fields_options, record_object = record_object, nil if > record_object.is_a?(Hash) && record_object.extractable_options? > fields_options[:builder] ||= options[:builder] > fields_options[:parent_builder] = self > fields_options[:namespace] = > fields_options[:parent_builder].options[:namespace] > > case record_name > when String, Symbol > if nested_attributes_association?(record_name) > return fields_for_with_nested_attributes(record_name, > record_object, fields_options, block) > end > else > record_object = record_name.is_a?(Array) ? record_name.last : > record_name > record_name = ActiveModel::Naming.param_key(record_object) > end > > index = if options.has_key?(:index) > "[#{options[:index]}]" > elsif defined?(@auto_index) > self.object_name = @object_name.to_s.sub(%r\[\]$/,"") > "[#{@auto_index}]" > end > record_name = "#{object_name}#{index}[#{record_name}]" > > @template.fields_for(record_name, record_object, fields_options, > &block) > end > > Notice this part: > > options[:builder] > > this options hash is no where to be defined. In argument list, there''s > only a fields_options hash. Reason why this matters to me is because I > am trying to override this method in my application_helper.rb in order > to extend it.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/3Mn0MtAYoIsJ. For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2013-Apr-03 09:07 UTC
Re: rails source fields_for has an options hash not defined anywhere
On Wednesday, April 3, 2013 6:21:59 AM UTC+1, eggie5 wrote:> > I want to know this too. Did you find out? > >That fields_for method is an instance method of FormBuilder, which has an attr_accessor :options Fred> On Wednesday, March 21, 2012 2:12:09 PM UTC-7, John Merlino wrote: >> >> Hey all, >> >> I looked at source code for fields_for: >> >> def fields_for(record_name, record_object = nil, fields_options = {}, >> &block) >> fields_options, record_object = record_object, nil if >> record_object.is_a?(Hash) && record_object.extractable_options? >> fields_options[:builder] ||= options[:builder] >> fields_options[:parent_builder] = self >> fields_options[:namespace] = >> fields_options[:parent_builder].options[:namespace] >> >> case record_name >> when String, Symbol >> if nested_attributes_association?(record_name) >> return fields_for_with_nested_attributes(record_name, >> record_object, fields_options, block) >> end >> else >> record_object = record_name.is_a?(Array) ? record_name.last : >> record_name >> record_name = ActiveModel::Naming.param_key(record_object) >> end >> >> index = if options.has_key?(:index) >> "[#{options[:index]}]" >> elsif defined?(@auto_index) >> self.object_name = @object_name.to_s.sub(%r\[\]$/,"") >> "[#{@auto_index}]" >> end >> record_name = "#{object_name}#{index}[#{record_name}]" >> >> @template.fields_for(record_name, record_object, fields_options, >> &block) >> end >> >> Notice this part: >> >> options[:builder] >> >> this options hash is no where to be defined. In argument list, there''s >> only a fields_options hash. Reason why this matters to me is because I >> am trying to override this method in my application_helper.rb in order >> to extend it. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/pF1-awySinEJ. For more options, visit https://groups.google.com/groups/opt_out.