I have a form that displays a set of inputs. I also have a button, and when clicked, I make an ajax request which is supposed to replace the existing inputs with a different set of inputs.
All my ajaxy linking stuff up works fine. The problem is that I'm using a form_for
, so in order to display the new form inputs, I need the form builder instance.
<%= simple_form_for @order do |f| %>
<div id="info">
<%= render 'my_first_form_fields_partial', f: f %>
</div>
<%= link_to 'Change inputs', change_inputs_path, remote: true %>
<% end %>
I'd like my js.erb to look like this, but f
is only defined within the scope of the form in the view.
$('#info').html("<%= escape_javascript(render 'my_second_fields_partial', f: f) %>");
How can I work it so that I can get f
into that partial somehow?
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) %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With