开发者

has any one gotten acts_as_list to work on rails 3?

开发者 https://www.devze.com 2023-02-01 04:56 出处:网络
I installed by putting the following line in Gemfile and \'bundle install\': gem \'acts_as_list\', \'>= 0.1.0\'

I installed by putting the following line in Gemfile and 'bundle install':

gem 'acts_as_list', '>= 0.1.0'  

However, when I try to use it, the results are not as expected:

technician.move_to_top #works => position = 1  
technician.move_to_bottom #does not work properly; also makes position = 1  
technician.move_higher #does not work; returns nil  
technician.move_lower #does no开发者_StackOverflow中文版t work; also returns nil  

Does this plugin just doesn't work with rails 3 or am I missing a step?

here is the code I'm using:

class WorkQueue < ActiveRecord::Base  
  has_many :technicians, :order => "position"  
end  

class Technician < ActiveRecord::Base  
  belongs_to :work_queue  
  acts_as_list :scope => "work_queue_id" #I also tried using work_queue  
end  

this is the console:

wq = WorkQueue.new  
technician = Technician.last
wq.technicians << technician  


Don't use "acts-as-list" gem because this gem doesn't update for a long time.

Try this:

rails plugin install git://github.com/swanandp/acts_as_list.git


acts_as_list 0.2.0 is working for me in Rails 3.2.11 on Ruby 1.9.3. However, the << syntax for adding Tasks causes problems. I used list.tasks.create() instead.

Here is a sample test:

test "acts_as_list methods" do
  list = ToDoList.create(description: 'To Do List 1')

  task1 = list.tasks.create(description: 'Task 1')
  task2 = list.tasks.create(description: 'Task 2')
  task3 = list.tasks.create(description: 'Task 3')

  assert_equal 3, list.tasks.count
  assert_equal task1.id, list.tasks.order(:position).first.id
  assert_equal task3.id, list.tasks.order(:position).last.id

  # Move the 1st item to the bottom. The 2nd item should move into 1st
  list.tasks.first.move_to_bottom

  assert_equal 3, list.tasks.count
  assert_equal task2.id, list.tasks.order(:position).first.id
  assert_equal task1.id, list.tasks.order(:position).last.id
end

When creating a new task unrelated to a to_do_list, acts_as_list will assign a position scoped against to_do_list_id == nil. Later adding an existing task to a to_do_list with << does not update the task position so acts_as_list gets confused about the positions.

Check your test.log to see the SQL statements generated by acts_as_list to get a clear picture of what is happening in your particular app.

Since it appears that your technicians are assigned after the work_queue tasks are created, you may need to manually set or re-calculate the positions after calling '<<'. You might also consider moving acts_as_list to your TechnicianWorkQueue model so acts_as_list is only invoked when you create the relationship between Technician and WorkQueue.


Looks like it should work: http://www.railsplugins.org/plugins/317-acts-as-list?version_id=418

0

精彩评论

暂无评论...
验证码 换一张
取 消