Solution:
def render_associated_form(associated, opts = {})
associated = associated.is_a?(Array) ? associated : [associated]
# preserve association proxy if this is one
opts.symbolize_keys!
(opts[:new] - associated.select(&:new_record?).length).times
{ associated.build } if opts[:new]
unless associated.empty?
name = extract_option_or_class_name(opts, :name,
associated.first)
partial = opts[:partial] || name
local_assign_name = partial.split('/').last.split('.').first
associated.map do |element|
fields_for_associated(element, (opts[:fields_for] ||
{}).merge(:name => name)) do |f|
template = @template.render({:partial => "#
{partial}", :locals => {local_assign_name.to_sym => element, :f =>
f}.merge(opts[:locals] || {})}.merge(opts[:render] || {}))
template.gsub!('&', '&') if opts[:fields_for] && opts
[:fields_for][:javascript]
template
end
end
end
end
This line is important: template.gsub!('&', '&') if opts
[:fields_for] && opts[:fields_for][:javascript]