Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As I said in my comments, I can show you what I do but it may be too clever by half or there may be a much more direct way to accomplish it that I just don't know about.</p> <p>For me, I would want all my committees to show in the same order each time so I first prebuild all the possible associations in my <code>new</code> and <code>edit</code> controllers as well as the failure case of <code>create</code> and <code>update</code>.</p> <p>I have code here which will make sure all the possible associations exist, respect ones that are saved and orders them the same way each time:</p> <p><a href="https://stackoverflow.com/questions/13599519/rails-how-do-i-prepend-or-insert-an-association-with-build">Rails: How do I prepend or insert an association with build?</a></p> <p>Then in my view, I use checkboxes to delete the ones I don't want saved.</p> <pre><code>= f.fields_for :committee_meetings do |cm| = cm.check_box :_destroy, {:checked =&gt; cm.object.persisted?}, 0, 1 = cm.label :_destroy, cm.object.committee.name = cm.hidden_field :committee_id, :value =&gt; f.object.committee.id </code></pre> <p>Basically, I've reversed the polarity of the checkbox so it will send <code>:_destroy</code> if it's not checked or nothing if it is.</p> <p>It works for me, and I'm sure you can get it to work for you. I'm afraid I can't say why your code is failing since I don't understand why it's even partially working. I'd prefer to just fix your issue, but perhaps this alternate method will help.</p>
    singulars
    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.
    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