Here is the scenario. On my project#new form I need to set up customer. Currently, user selects customer from a dropdown. I want to render new customer form instead. However for now when the form pops up it appears twice.
Not sure what is going one.
My project form with link to customer form
`<%= form_for(@project) do |f| %>
...
<%= link_to 'Create Customer', new_customer_path, :remote => true %>`
which renders new.js.erb
$(document).ready(function(){
$('<div id="new_customer_dialog"></div>')
.html('<%= escape_javascript render(:partial => 'fields') %>')
.dialog({
autoOpen: true,
modal: true,
title: 'Add a Customer',
buttons: { 'Create Customer' : function(){ $(this).find("form").submit(); }, 'Cancel' : function(){ $(this).dialog("close"); } },
});
});
and finally the partial
<%= form_for(@customer) do |f| %>
<div class="field">
<%= f.label :name %>
<%= f.text_field :_name %>
</div>
<% end %>
Was missing remote declaration in the form too