acts_as_list
acts_as_list copied to clipboard
Position cannot be lower than top issue
Hi,
I am getting the following error:
13:24:39 jobs.1 | 2022-04-09T12:24:39.428Z pid=35399 tid=25bz WARN: ArgumentError: position cannot be lower than top
13:24:39 jobs.1 | 2022-04-09T12:24:39.428Z pid=35399 tid=25bz WARN: /Users/user/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/acts_as_list-1.0.4/lib/acts_as_list/active_record/acts/list.rb:392:in `insert_at_position'
My code is as below:
Album.all.each do |album|
parent = album.collection
album_gi = GalleryItem.find_by(gallery_itemable: album)
parent_gi = GalleryItem.find_by(gallery_itemable: parent)
puts "Positioning parent Collection of '#{album.title}' into position #{album_gi.position}"
parent_gi.insert_at(album_gi.position)
end
It works perfectly until it reaches the first Album
. Surely it should just insert the parent_gi
to position 0 and move everything down 1 slot? Why is it trying to insert at a negative value rather than push everything else down like it does for the rest?
Hi @rctneil, it'll insert at whatever album_gi.position
is. Not knowing much about the structure of your code I can't really help more. The first step would be to figure out why album_gi.position
is 'lower' than your allowed lowest value (normally 1).
@brendon Thanks. Is the top of the list position 0 or 1? I'm trying to insert at 0.
It’s configurable but I think it defaults to 1. Check the README :)
@rctneil, I assume you managed to figure it out? If not, feel free to re-open this :)