has any one gotten acts_as_list to work on rails 3?
Asked Answered
F

3

5

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 not 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  
Frost answered 22/12, 2010 at 2:0 Comment(2)
could be that the positions are not in consecutive numbers?Earthwork
Facing the same problem when used gem acts_as_lists github.com/swanandp/acts_as_list . Have you found how to resolve it. I am using Rails 3.2.2Reine
N
0

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

Nasho answered 22/12, 2010 at 2:2 Comment(6)
I've read that and all others I could find, but none of them could make it work properly. Are you using it?Frost
why are you specifying the version. I would think you want the most recent for rails3, which is 0.1.2Nasho
the current installed version is 0.1.2. Is it the way I'm building the list? wq.technicians << technicianFrost
post your addition code - that looks wrong to me, but I need to see it in contextNasho
I edited the question to include the code (it's more readable up there)...thanks for taking time to help me with this...Frost
can a technician only belong to one work queue or many? i think this may be your problem. something that belongs_to something else can only have one association to that other model. I think you really want a has_and_belongs_to_many association. guides.rubyonrails.org/…Nasho
G
9

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
Glutathione answered 20/5, 2011 at 3:55 Comment(1)
You can use the gem acts_as_list.Epifaniaepifano
V
3

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.

Ventilator answered 21/4, 2013 at 15:8 Comment(0)
N
0

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

Nasho answered 22/12, 2010 at 2:2 Comment(6)
I've read that and all others I could find, but none of them could make it work properly. Are you using it?Frost
why are you specifying the version. I would think you want the most recent for rails3, which is 0.1.2Nasho
the current installed version is 0.1.2. Is it the way I'm building the list? wq.technicians << technicianFrost
post your addition code - that looks wrong to me, but I need to see it in contextNasho
I edited the question to include the code (it's more readable up there)...thanks for taking time to help me with this...Frost
can a technician only belong to one work queue or many? i think this may be your problem. something that belongs_to something else can only have one association to that other model. I think you really want a has_and_belongs_to_many association. guides.rubyonrails.org/…Nasho

© 2022 - 2024 — McMap. All rights reserved.