Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

position: 0 now makes model pushed to top? #110

Closed
USvER opened this issue Mar 15, 2014 · 9 comments
Closed

position: 0 now makes model pushed to top? #110

USvER opened this issue Mar 15, 2014 · 9 comments

Comments

@USvER
Copy link

USvER commented Mar 15, 2014

After update i got weird issues with sorting.
After investigation i have found that new items got pushed to top, and not to bottom as described...
So model with position: 0 results into position: 1.
Is this new behaviour, or i have some issues in my code? Maybe with scope(i have scope on multiple fields) but how it relates to this?

@USvER
Copy link
Author

USvER commented Mar 15, 2014

For now, fixed my issue with move_to_bottom function in the controller.
But this is really no cool!

@USvER
Copy link
Author

USvER commented Mar 16, 2014

Any suggestions to set "new items at the bottom of the list" as a default behaviour?
It's so frustrating when i have this sorting issue poping here and there every day...

@swanandp
Copy link
Collaborator

Let me look at this. What is your gem version?
On 17-Mar-2014 4:45 am, "USvER" notifications@github.com wrote:

Any suggestions to set "new items at the bottom of the list" as a default
behaviour?
It's so frustrating when i have this sorting issue poping here and there
every day...

Reply to this email directly or view it on GitHubhttps://github.com//issues/110#issuecomment-37774865
.

@USvER
Copy link
Author

USvER commented Mar 17, 2014

  • acts_as_list (0.4.0)
  • rails (4.0.3)
  • ruby (2.1.1)

@neutralino1
Copy link

Is this related to #109 ?

@nickpearson
Copy link

I had this issue as well, and I fixed it (for my use case, at least) with the following mixin:

module ActsAsListFix
  # clear the default position value, because having it present
  # causes acts_as_list to insert the record at that position
  def self.included(base)
    base.after_initialize do
      if new_record? && (pos = send(position_column)) &&
         pos == self.class.column_defaults[position_column]
        send("#{position_column}=", nil)
      end
    end
  end
end

Just place the acts_as_list_fix.rb file in an auto-loaded path (like <Rails.root>/lib) and include it with any acts_as_list declarations, e.g.:

class Floor < ActiveRecord::Base
  acts_as_list scope: :building_id
  include ActsAsListFix
end

This is an update to my solution to this problem from a few years ago. That wasn't working for me anymore after upgrading to Rails 4.1 and Ruby 2.1, but this new one is working for me so far.

Hopefully this behavior of ignoring the default value of the position database field can be worked into the acts_as_list gem itself, and if not, I at least hope it helps someone else who has trouble with this. (Thanks @swanandp for maintaining this gem!)

@brendon
Copy link
Owner

brendon commented Apr 17, 2016

Is this still a problem? Instead of a monkey patch it'd be good if we could fix it. New items should go at the bottom of the list by default. Have you tried removing the default value from that column?

@USvER
Copy link
Author

USvER commented Apr 18, 2016

Sorry, i'm not having access to that project anymore.

@brendon
Copy link
Owner

brendon commented Apr 18, 2016

Ok, I'll close this. If someone can reproduce this with a failing test then we'll look into it.

@brendon brendon closed this as completed Apr 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants