Forum: Ruby on Rails rails source fields_for has an options hash not defined anywhere

1d4a45a695b48edc70359ca6d015e2f4?d=identicon&s=25 John Merlino (johnmerlino)
on 2012-03-21 22:13
(Received via mailing list)
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.
556728451f3406da709d2598233804b7?d=identicon&s=25 eggie5 (Guest)
on 2013-04-03 18:11
(Received via mailing list)
I want to know this too. Did you find out?
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2013-04-03 19:44
(Received via mailing list)
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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.