I have a rails form with nested views using fields_for:
new.html.erb
<%= form_for @leads do |f| %>
<%= f.text_field :some_field %>
<%= f.fields_for :tickets do |ticket_builder| %>
<%= render 'tickets', f: ticket_builder %>
<% end %>
<% end %>
_tickets.html.erb
f.text_field :some_other_field
There are situations where I need to add the tickets partial via ajax, and therefore I need to render that partial via a controller action:
def add_ticket
resp = {}
resp[:html_options] = render_to_string(partial: "tickets", locals: { f: nil } )
render text: resp.to_json
end
Obviously this blows up since the f variable passed to the partial is nil, where it should be a form builder.
How can I pass a form builder to the partial from the controller?