Rails 3 + Ajax: how to access my local form builder instance Rails 3 + Ajax: how to access my local form builder instance ajax ajax

Rails 3 + Ajax: how to access my local form builder instance


Can you use fields_for in your partial, and pass the @object to it? That way you don't need to pass a form builder?

partial:

<%= fields_for object do |f| %>  f.text_field :field_name<% end %>


$('#info').html("<%= escape_javascript(render 'my_second_fields_partial', object: @object) %>


Many thanks to @flyfish, his answer helped me solved how to do ajax with nested attributes. I took @flynfish answer and tweeked it for my situation:

<%= fields_for object do |f| %>  <%= f.fields nested_object, child_index: Time.now.to_i do |builder| %><% end %>

$('#info').html("<%= escape_javascript(render 'my_second_fields_partial', object: @object), nested_object: @nested_object %>

The child_index is important for without it your params hash will build with [0] and will then overlay any other records built with the initial fields_for which starts at zero and increments from there.