Skip to content

Instantly share code, notes, and snippets.

@scottmessinger
Created August 18, 2010 19:51
Show Gist options
  • Save scottmessinger/535951 to your computer and use it in GitHub Desktop.
Save scottmessinger/535951 to your computer and use it in GitHub Desktop.
From Courses controller
def sort_roots
sequence_groups = []
#turn hash into array
params[:sequence_groups].each do |k, v|
sequence_groups << v
end
# First, assign the correct group_id
root_sequences = []
sequence_groups.each do |sg|
group_id = sg.keys[0].to_s.gsub('sequence_group_', '')
sg.values[0].each do |s|
sequence_id = s.to_s.gsub("sequence_", "")
Sequence.set(sequence_id, :sequence_group_id => group_id )
root_sequences << sequence_id
end
end
#send the array to the method that assigns the position numbers
root_sequence_array = []
root_sequences.each do |r|
root_sequence_array << Sequence.find(r)
end
Sequence.reorder_siblings(root_sequence_array)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment