Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing acts_as_list with has_many :through in rails
    primarykey
    data
    text
    <p>I have a rails app I'm trying to set up with sortable lists using the acts_as_list plugin. The position field in the db is getting updated, but when the page is rendered, the order is not considered. I'm looking for some help, I guess. </p> <p>Here are my models...</p> <pre><code>class QuestionMembership &lt; ActiveRecord::Base belongs_to :form belongs_to :question acts_as_list end class Form &lt; ActiveRecord::Base has_many :question_memberships has_many :questions, :through =&gt; :question_memberships end class Question &lt; ActiveRecord::Base has_many :question_memberships has_many :forms, :through =&gt; :question_memberships acts_as_list end </code></pre> <p>And the sloppy view code that gives me the list...</p> <pre><code>&lt;% @form.question_memberships.each do |qm| %&gt; &lt;% q_id = "question_#{qm.id}" %&gt; &lt;li class="question" id=&lt;%= q_id %&gt; &gt; &lt;div style="color: #999; font-size: 8pt"&gt; &lt;%=h qm.question.content %&gt; &lt;/div&gt; &lt;/li&gt; &lt;%= draggable_element(q_id, :revert=&gt;true) %&gt; &lt;% end %&gt; </code></pre> <p>The drag and drop works for the reordering. The position value updates in the DB for the QuestionMembership objects and the page actually shows the reorder correctly. The problem is that on a page reload, it defaults back to whatever order it feels like. I think it defaults to the question id for the order instead of the question_membership position, but I'm not sure.</p> <p>Any ideas on how I can make it actually order on the initial render by the position field of the QuestionMembership?</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