Sorting deeply nested attributes in Rails
- by Senthil
I want to be able to drag and drag App model which is nested under Category model.
http://railscasts.com/episodes/196-nested-model-form-part-1
's the Railscast I've tried to follow.
Category controller
def move
params[:apps].each_with_index do |id, index|
Category.last.apps.update(['position=?', index+1], ['id=?', Category.last.id])
end
render :nothing => true
end
I'm able to sort Categories with something similar, but since I'm updating an attribute, I'm having trouble.
def sort
params[:categories].each_with_index do |id, index|
Category.update_all(['position=?', index+1], ['id=?', id])
end
render :nothing => true
end
Any help is appreciated.