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

add_new_at: :top does not work #296

Closed
jonhue opened this issue Jan 13, 2018 · 2 comments
Closed

add_new_at: :top does not work #296

jonhue opened this issue Jan 13, 2018 · 2 comments

Comments

@jonhue
Copy link

jonhue commented Jan 13, 2018

class Author < ApplicationRecord
    has_many :weather_locations, -> { order(position: :asc) }, class_name: 'Weather::Location', dependent: :destroy
end

class Weather::Location < ApplicationRecord
    acts_as_list scope: [:author, :visit], add_new_at: :top
    belongs_to :author, optional: true
    belongs_to :visit, optional: true
end
$ a = Author.first
$ a.weather_locations.create
$ a.weather_locations.create
$ a.weather_locations.each { |l| p l.position }
1
1

Whenever I create new records (either using add_new_at: :top or by manually utilizing insert_at(1)) the position of existing records does not get adjusted. What am I doing wrong?

@brendon
Copy link
Owner

brendon commented Jan 15, 2018

Off the top of my head I think you're supposed to specify the full column name when using the array scope syntax:

acts_as_list scope: [:author_id, :visit_id], add_new_at: :top

Let me know if that doesn't work.

@jonhue
Copy link
Author

jonhue commented Jan 16, 2018

Thanks for your help @brendon ! Works perfectly

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

2 participants