# Acts\_as\_list/acts\_as\_tree - spostare i nodi

**URL:** <https://www.ruby-forum.com/t/acts-as-list-acts-as-tree-spostare-i-nodi/141202>\
**Category:** IT\
**Created:** [June 23, 2008, 3:50pm UTC](https://www.ruby-forum.com/t/acts-as-list-acts-as-tree-spostare-i-nodi/141202 "2008-06-23T15:50:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![arcoder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@arcoder](https://www.ruby-forum.com/u/arcoder)\
**Post date:** [June 23, 2008, 3:50pm UTC](https://www.ruby-forum.com/t/acts-as-list-acts-as-tree-spostare-i-nodi/141202/1 "2008-06-23T15:50:36Z")

</div>

Ciao,  
sto modificando uno scaffold per spostare i nodi.  
Quindi nella vista ho messo una select name=“move” con

sposta verso sopra sposta verso sotto

Nel controller ho la funzione update dello scaffold(leggermente  
modificata):  
la tabella categories ha ovviamente i campi ‘position’ e ‘parent\_id’.

def update  
@category = Category.find(params[:id])  
if params[:move]==1  
@category.move\_to\_top  
elsif params[:move]==1  
@category.move\_to\_bottom  
end  
@category.reload  
respond\_to do |format|  
if @category.update\_attributes(params[:category])  
flash[:notice] = ‘Category was successfully updated.’  
format.html { redirect\_to(@category) }  
format.xml { head :ok }  
else  
format.html { render :action =\> “edit” }  
format.xml { render :xml =\> @category.errors, :status =\>  
:unprocessable\_entity }  
end  
end  
end

Ma quando effettuo l’update il campo ‘position’ non cambia e il nodo  
rimane fermo, dove sbaglio?

Saluti

Alberto

---

<div class="post-metadata">

**Author:** ![arcoder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@arcoder](https://www.ruby-forum.com/u/arcoder)\
**Post date:** [June 23, 2008, 3:52pm UTC](https://www.ruby-forum.com/t/acts-as-list-acts-as-tree-spostare-i-nodi/141202/2 "2008-06-23T15:52:33Z")

</div>

EDIT:  
ho copiato qui sul forum male queste 2 righette:  
VERSIONE GIUSTA  
if params[:move]==1  
@category.move\_to\_top  
elsif params[:move]==0  
@category.move\_to\_bottom  
end  
VERSIONE SBAGLIATA  
if params[:move]==1  
@category.move\_to\_top  
elsif params[:move]==1  
@category.move\_to\_bottom  
end
