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.
Here are my models...
class QuestionMembership < ActiveRecord::Base
belongs_to :form
belongs_to :question
acts_as_list
end
class Form < ActiveRecord::Base
has_many :question_memberships
has_many :questions, :through => :question_memberships
end
class Question < ActiveRecord::Base
has_many :question_memberships
has_many :forms, :through => :question_memberships
acts_as_list
end
And the sloppy view code that gives me the list...
<% @form.question_memberships.each do |qm| %>
<% q_id = "question_#{qm.id}" %>
<li class="question" id=<%= q_id %> >
<div style="color: #999; font-size: 8pt">
<%=h qm.question.content %>
</div>
</li>
<%= draggable_element(q_id, :revert=>true) %>
<% end %>
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.
Any ideas on how I can make it actually order on the initial render by the position field of the QuestionMembership?