I have a rails application that I am trying to configure using sorted lists using the act_as_list plugin. The position field in db is updated, but when the page is displayed, the order is not taken into account. I think I'm looking for some help.
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 a sloppy browsing code that gives me a 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 %>
Drag and drop works to reorder. The position value is updated in the database for QuestionMembership objects, and the page actually shows the correct reordering. The problem is that when you reload the page, it defaults to whatever order it looks like. I think it by default sets the question id for the order instead of the question_membership position, but I'm not sure.
, QuestionMembership?