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

decrement_positions_on_lower_items method #17

Closed
piccio opened this issue Oct 12, 2011 · 2 comments
Closed

decrement_positions_on_lower_items method #17

piccio opened this issue Oct 12, 2011 · 2 comments

Comments

@piccio
Copy link

piccio commented Oct 12, 2011

I found an odd behaviour when destroing a list item. when it's invoked decrement_positions_on_lower_items method al the lower items' position are set to deleted item's position. for example:

[ < Item id:1, position: 1 >, < Item id:2, position: 2 >, < Item id:3, position: 3 >, < Item id:4, position: 4 > ]

if I delete the item with id = 2 the resulting list is:

[ < Item id:1, position: 1 >, < Item id:3, position: 2 >, < Item id:4, position: 2 > ]

instead of:

[ < Item id:1, position: 1 >, < Item id:3, position: 2 >, < Item id:4, position: 3 > ]

I resolved overriding decrement_positions_on_lower_items method:

def decrement_positions_on_lower_items
return unless in_list?
acts_as_list_class.each do |l|
l.update(
"#{position_column} = (#{position_column} - 1)",
"#{scope_condition} AND #{position_column} > #{send(position_column).to_i}"
)
end
end

@swanandp
Copy link
Contributor

swanandp commented Nov 2, 2011

I'll take a look at this one later today. If you already have a commit, then please send a pull request and I'll merge it.

@swanandp
Copy link
Contributor

@piccio: Sorry for the really really late response, but I think test_delete_middle tests this behavior and this might have been fixed during last couple of merges / commits.

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