brendon / acts_as_list

An ActiveRecord plugin for managing lists.
http://brendon.github.io/acts_as_list/
MIT License
2.05k stars 356 forks source link

`add_new_at: :top` does not work #296

Closed jonhue closed 6 years ago

jonhue commented 6 years ago
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 commented 6 years ago

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 commented 6 years ago

Thanks for your help @brendon ! Works perfectly