我正在使用acts_as_list gem,但在创建新的Object时,位置应自动增加大小和订单位置ASC。
LessonPage模型
class LessonPage < ActiveRecord::Base
acts_as_list :scope => 'lesson_id = #{lesson_id}'
default_scope order('position ASC')
end
选择
SELECT "lesson_pages".* FROM "lesson_pages" ORDER BY position ASC, "lesson_pages".id desc
插入 - 首先
INSERT INTO "lesson_pages" ("created_at", "lesson_id", "position", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Sun, 16 Oct 2011 11:55:27 CEST +02:00], ["lesson_id", 2], ["position", 1], ["updated_at", Sun, 16 Oct 2011 11:55:27 CEST +02:00]]
第二
INSERT INTO "lesson_pages" ("created_at", "lesson_id", "position", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Sun, 16 Oct 2011 11:57:15 CEST +02:00], ["lesson_id", 2], ["position", 2], ["updated_at", Sun, 16 Oct 2011 11:57:15 CEST +02:00]]
第三
INSERT INTO "lesson_pages" ("created_at", "lesson_id", "position", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Sun, 16 Oct 2011 11:58:13 CEST +02:00], ["lesson_id", 2], ["position", 2], ["updated_at", Sun, 16 Oct 2011 11:58:13 CEST +02:00]]
这里失败了,因为位置应该是3而不是2.如何解决这个问题? 谢谢!
答案 0 :(得分:1)
我认为这是由commit修复的,但此修复后没有发布。我认为你应该使用github的代码。
使用它:
gem 'acts_as_list', :git => 'https://github.com/swanandp/acts_as_list.git'