Skip to content

Instantly share code, notes, and snippets.

@m3talsmith
Created January 29, 2015 14:44
Show Gist options
  • Save m3talsmith/c88d2e80bdb4d5909879 to your computer and use it in GitHub Desktop.
Save m3talsmith/c88d2e80bdb4d5909879 to your computer and use it in GitHub Desktop.
a demonstration of updating a sorted item
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