Sorting deeply nested attributes in Rails
Posted
by Senthil
on Stack Overflow
See other posts from Stack Overflow
or by Senthil
Published on 2010-03-08T05:01:55Z
Indexed on
2010/03/08
5:06 UTC
Read the original article
Hit count: 798
ruby-on-rails
|nested-attributes
I want to be able to drag and drag App model which is nested under Category model.
'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.
© Stack Overflow or respective owner