Note that there are some explanatory texts on larger screens.

plurals
  1. PORails partial form in a form
    primarykey
    data
    text
    <p>I have a Rails app with Expenses that belongs_to Vendors.</p> <p>While the user is adding a new Expense, they might need to add a new Vendor.</p> <p>I thought I could just add a button and a Vendor partial to the Expense form.</p> <p>Like this:</p> <pre><code>&lt;%= simple_form_for @expense, :html =&gt; {:class =&gt; 'form-horizontal'} do |f| %&gt; &lt;div class="span5"&gt; &lt;a data-toggle="modal" href="#vendorform"&gt; &lt;p class="pull-right btn btn-primary btn-mini"&gt;New Vendor&lt;/p&gt;&lt;/a&gt; &lt;%= render :partial =&gt; "vendors/vendorform" %&gt; &lt;/a&gt; &lt;%= f.association :vendor, :label_method =&gt; :vendor_name, :label =&gt; 'Vendor', collection: Vendor.order('vendor_name ASC') %&gt; </code></pre> <p>The _vendorform.html.erb looks like this:</p> <pre><code>&lt;div id="vendorform" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="vendorformLabel" aria-hidden="true"&gt; &lt;div class="modal-header"&gt; &lt;a class="close" data-dismiss="modal"&gt;&amp;#215;&lt;/a&gt; &lt;h4 id="vendorformLabel"&gt;Add Vendor&lt;/h4&gt; &lt;/div&gt; &lt;div class="modal-body"&gt; &lt;%= simple_form_for Vendor.new do |f| %&gt; (bunch of fields) &lt;/div&gt; &lt;div class="modal-footer"&gt; &lt;%= f.submit 'Save Vendor', :class =&gt; 'btn btn-mini btn-primary' %&gt; &lt;a class="btn btn-mini" data-dismiss="modal" href="#"&gt;Close&lt;/a&gt; &lt;% end %&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>This partial shows up OK. But, the Vendor record doesn't get created. The submit of the partial actually somehow triggers the submit for the Expense. The page comes back with all of the required Expense fields red.</p> <p>I think it's posting to the Expenses controller when the <code>f.submit</code> button in the Vendor partial is pressed !!!</p> <p>Do I need something in the Expense controller?</p> <p>Or is there a better way?</p> <p>Thanks for the help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload