Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The question is a little vague. My interpretation is that you want to group similar selections by attribute as they appear in the form. Kind of like this:</p> <ul> <li>form for Match <ul> <li>form for Selections <ul> <li>fields for Selection with attribute A</li> <li>fields for Selection with attribute A</li> <li>fields for Selection with attribute A</li> <li>fields for Selection with attribute B</li> <li>fields for Selection with attribute B</li> <li>fields for Selection with attribute C</li> <li>etc.</li> </ul></li> </ul></li> </ul> <p>The group_by operator is not what you want. It will condense all selections that meet the criteria to a single entry.</p> <p>The better option would be to use the order option when populating the list for the selection. Might even work out better for you to specify that order in the association. This will do what you want without changing your form.</p> <pre><code> has_many :selections, :order =&gt; "attribute" </code></pre> <p>But this will cause all your selection queries from match to be ordered by attributes. If this is a problem, you could add a second has_many relationship for selections.</p> <pre><code> has_many :selections has_many :grouped_selections, :class_name =&gt; "selection", :order =&gt; "attribute" accepts_nested_attributes_for :selections, :grouped_selections :allow_destroy =&gt; true </code></pre> <p>And all that needs to change in your form is <code>&lt;% form.fields_for :grouped_selections %&gt;</code>.</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