Coder Social home page Coder Social logo

Comments (7)

matthewfarrell avatar matthewfarrell commented on June 1, 2024

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.

swanandp avatar swanandp commented on June 1, 2024

@shaileshparamisoft I think upgrading to latest should solve your problem.

from acts_as_list.

swanandp avatar swanandp commented on June 1, 2024

But if not, let me know.

from acts_as_list.

shaileshkalamkar avatar shaileshkalamkar commented on June 1, 2024

@swanandp Yes, the issue has been resolved.
Thanks for you reply.

from acts_as_list.

daz avatar daz commented on June 1, 2024

I'm still getting nil when setting it up, because all my position columns are nil.

from acts_as_list.

mkolodziej avatar mkolodziej commented on June 1, 2024

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.

redbar0n avatar redbar0n commented on June 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.