Comments (7)
I too had this problem after setting up acts_as_list when there was existing data in the table. It appears that move_lower/move_higher will not move an item if the position column value is null, or if only one item has a position. This makes sense, but is not immediately obvious. To resolve this, I set a default position for all items using a migration:
execute "UPDATE sortable_table SET position = id"
Source: http://nicholshayes.co.uk/blog/?p=344
from acts_as_list.
@shaileshparamisoft I think upgrading to latest should solve your problem.
from acts_as_list.
But if not, let me know.
from acts_as_list.
@swanandp Yes, the issue has been resolved.
Thanks for you reply.
from acts_as_list.
I'm still getting nil when setting it up, because all my position columns are nil.
from acts_as_list.
I had a Category hierarchy in my app and had the same problem with null position values. I solved it by adding this method to the migration that created the position column:
update_position_recursively(Category.roots)
def update_position_recursively(categories)
categories.each_with_index do |cat, idx|
cat.update_attribute(:position, idx)
update_position_recursively(cat.subcategories) unless cat.subcategories.empty?
end
end
This is assuming Category.roots
would return all roots and that I have has_many :subcategories ...
in my Category
class
from acts_as_list.
I fixed this problem by making a rake task (as DB updates generally shouldn't be done in migrations). See: https://stackoverflow.com/a/15531843/380607
from acts_as_list.
Related Issues (20)
- Tests for Ruby 2.7 and 3.0 HOT 3
- Is it possible to run callback for all updated records? HOT 3
- Limiting the list size HOT 1
- touch parent broken on destroy HOT 4
- Position cannot be lower than top issue HOT 4
- How to move an item to other scope at specific position HOT 3
- Attachments sorting / has_many_attached HOT 1
- Shifted records are not broadcast by Turbo Streams HOT 4
- How can I use act_as_list with a has_many_attached association (ActiveStorage, Rails 7) HOT 3
- Can I scope it based on a column in another table? HOT 14
- Bug: Possibly duplicated positions if not given `add_new_at: top` option HOT 6
- Does positioning work on nil? HOT 1
- Reorder based on scope HOT 1
- Composite primary key support HOT 2
- Scoping by attribute and specific created_at date HOT 5
- Issue with `move_to_bottom` and `bottom cannot be lower than top` with an empty list HOT 5
- How does one update position on a self referential model? HOT 1
- 2 Questions HOT 7
- STI support HOT 6
- adding list item with position not in sequence messes the existing list item positions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from acts_as_list.