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