Created
January 29, 2015 14:44
-
-
Save m3talsmith/c88d2e80bdb4d5909879 to your computer and use it in GitHub Desktop.
a demonstration of updating a sorted item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Step | |
attr_accessor :id, :position | |
// all_steps = [Step.new(id: 1), Step.new(id: 2), Step.new(id: 3)] | |
def move_to(position) | |
new_steps = all_steps | |
new_step.delete_at(new_steps.index(self)) | |
new_steps.insert(position, self) | |
new_steps.each_with_index do |step, index| | |
step.position = index | |
step.save! | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment