Forum: Ruby on Rails acts_as_list sorting issue

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
9e7cdfa62c6bc2a155f2f7950484e573?d=identicon&s=25 Brandon S. (deniedlates)
on 2007-02-01 06:40
Hi All,

I am using acts_as_list to sort photographs within photo albums.

So I have two models:

Photograph (belongs_to :photo_album)
PhotoAlbum (has_many :photographs)

Everything works great, until I update the properties of a photograph by
linking it to a different album.  acts_as_list is not recognizing that
the parent_id of my photograph has changed, thus the position field in
my photographs table is not being updated properly.

What is the proper way to update the parent/child records when a child
is being linked to a different parent?

Thanks in advance for your help.
9e7cdfa62c6bc2a155f2f7950484e573?d=identicon&s=25 Brandon S. (deniedlates)
on 2007-02-01 20:21
I figured this one out.  When I update a child record, I compare the old
parent_id  to the new parent_id.  If they are different, I execute a
move_to_bottom command on my child record.  This will push the child
record to the bottom of the new category, and will update my position
column automatically.  Hooray for Rails and acts_as_list.
This topic is locked and can not be replied to.