我有一个rails应用程序我正在尝试使用acts_as_list插件设置可排序列表.数据库中的位置字段正在更新,但在呈现页面时,不会考虑订单.我想,我正在寻求帮助.
这是我的模特......
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
以及给我列表的草率视图代码......
<% @form.question_memberships.each do |qm| %> <% q_id = "question_#{qm.id}" %>
拖放适用于重新排序.位置值在DB中为QuestionMembership对象更新,页面实际上正确显示了重新排序.问题是在页面重新加载时,它默认返回到它的感觉顺序.我认为它默认为订单的问题ID而不是question_membership位置,但我不确定.
关于如何通过QuestionMembership的位置字段对初始渲染进行实际排序的任何想法?
最终版本:
class QuestionMembership < ActiveRecord::Base belongs_to :form belongs_to :question acts_as_list :scope => :form end class Form < ActiveRecord::Base has_many :question_memberships, :order => "position" has_many :questions, :through => :question_memberships end class Question < ActiveRecord::Base has_many :question_memberships, :order => "position" has_many :forms, :through => :question_memberships acts_as_list :scope => :form end