Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Craig, it sounds like what you are looking for is accepts_nested_attributes_for which is a much better way of handling nested models in a form.</p> <p>Rather than just steal all of Ryan's work and repost it here, I'll just give you a link to his screencast: </p> <p><a href="http://railscasts.com/episodes/196-nested-model-form-part-1" rel="nofollow noreferrer">http://railscasts.com/episodes/196-nested-model-form-part-1</a></p> <p>This is based off his complex forms series.</p> <p>You should be able to taylor this tutorial to what you are trying to do, but if not I'd be happy to help.</p> <p><strong>EDIT:</strong></p> <p>Alright, after looking at your code, there are a few things causing you problems. :)</p> <p>First of all, with associations, you don't need to pull an extra collection for billings, i.e.:</p> <pre><code>@host = Host.find(params[:id]) @voips = Voip.find(:all) @custsupps = Custsupp.find(:all) @payments = Payment.find(:all) @billings = Billing.find(:all) # &lt;-- This is not needed and causing your problems </code></pre> <p>The association setup in the model does this all for you. This is part of the magic of rails. :D</p> <p>Now, it is important to note that when using associations you need to make sure that the objects are actually associated. In other words, if you have 3 Billings objects in your database and they are not associated with your Host object, they won't show up in the form.</p> <p>If you are trying to associate a billing TO a Host using a checkbox you are going to want to take a different approach, because your form with only display Billings <em>already associated</em> with your Host.</p> <p>If your just trying to edit or modify existing Billings that are associated to the Host, where the checkbox represents a 'paid' attribute (a boolean) for instance, then this approach is fine and your form code would look something like this:</p> <pre><code>&lt;% f.fields_for :billings do |b| %&gt;&lt;br /&gt; &lt;%= b.check_box :paid %&gt; &lt;%= b.title %&gt; &lt;% end %&gt; </code></pre> <p>So perhaps clarify what your trying to accomplish from a functionality standpoint and we can find a better solution.</p>
 

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