Karen Jenkin
2006-Sep-15 06:13 UTC
Changing list membership (in acts_as_list relationship)
Hi,
I''m going a little nuts trying to move an "article" from one
"block"
list to another "block" list.
The basics are -> each "block" has many articles that also act as a
list.
So an article has a block_id and position.
All relationships are setup OK, as adding and moving articles within a
block are fine. It''s just when an article is moved to a different
block
that things get hairy. This should be relatively easy, but it isn''t
doing what I want exactly - the moved article''s position is never set
to
be the next number in the new block''s list.
I''ve tried several variations in my article model''s
change_block
method() to get this to work, such as calling delete on the old block,
explicitly setting the position to nil before assigning to the new
block, doing multiple saves during the move process, etc.
The latest incarnation of the method is:
def change_block(new_block)
Article.transaction(self, new_block) do
self.position = nil
self.save!
new_block.articles << self
self.save!
end
end
which results in a nil position for the moved article (note: it does
have the new block id set). Other variants has the article keeping
it''s
old position value. Yuck!
Cheers,
Karen
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---