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

Added ability to set item positions directly (e.g. In a form) #38

Merged
merged 5 commits into from
Jun 30, 2012

Conversation

dubroe
Copy link
Contributor

@dubroe dubroe commented Jun 2, 2012

I'm working on an e-commerce site and one aspect of the site is that vendors are able to manipulate their menus. Here is an example of a test menu: https://skitch.com/dubroe/86en1/rhubs-menu-creator-test.

When a menu item is clicked, the vendor is presented with a form in which he can update the menu item attributes, including the item's position in the list:
https://skitch.com/dubroe/86ena/rhubs-edit-menu-item-test
https://skitch.com/dubroe/86edt/screen-shot-2012-06-02-at-1.58.03-pm

Before this patch, doing so messed everything up. Say I had 8 items in the menu, and I wanted to move the item in position 6 to position 4, this would end up with the positions being: 1,2,3,4,4,5,7,8. Basically the other positions weren't updated as they should be.

I've added an "after_update :update_positions" callback which checks to see if two items have the same position, and if they do, update the positions using the already existing "shuffle_positions_on_intermediate_items" function.

I had to make a small change to that function so that you can pass in an ID to ignore, so that the recently changed position doesn't get changed right after it was set.

Please let me know if you have any questions or issues with my code. I'm happy to make any modifications that you suggest. Overall though I think this is an important feature to add to this gem as without it lists are vulnerable to being corrupted if people manually update item positions.

Thanks,

~Elan Dubrofsky

@dubroe
Copy link
Contributor Author

dubroe commented Jun 26, 2012

Did you get a chance to read this by any chance? Curious to know your thoughts.

@swanandp
Copy link
Contributor

I didn't get time to try it out, but I am going to merge it and review later! Thanks for contributing!

@swanandp swanandp closed this Jun 30, 2012
@swanandp swanandp reopened this Jun 30, 2012
swanandp added a commit that referenced this pull request Jun 30, 2012
Added ability to set item positions directly (e.g. In a form)
@swanandp swanandp merged commit b716182 into brendon:master Jun 30, 2012
@zhengjia
Copy link

@dubroe @swanandp
It seems this pull request causes a problem when you have a scope in the list. For example acts_as_list :scope => :category. I have to downgrade the gem to 0.16 to get it working correctly

@dubroe
Copy link
Contributor Author

dubroe commented Jul 30, 2012

Haven't had a chance to look at this yet. @swanandp and @zhengjia do either of you have any insight into why it's breaking? @zhengjia any chance you can share some code to make it easier for me to recreate and then debug?

@zhengjia
Copy link

@swanandp and @dubroe
This is a failing test: zhengjia@3df5412

  1) Failure:
test_reordering(ScopedListTest) [/Users/zjia/code/acts_as_list/test/test_list.rb:365]:
<[4, 1, 2, 3]> expected but was
<[4, 1, 1, 2]>.

@swanandp
Copy link
Contributor

@zhengjia Thanks for following up on this, I am on it now.

@dubroe
Copy link
Contributor Author

dubroe commented Jul 31, 2012

Ok great. Let me know if you'd like me to take a crack.

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

Successfully merging this pull request may close these issues.

3 participants