# Update\_element\_function + sortable\_element = how to update?

**URL:** <https://www.ruby-forum.com/t/update-element-function-sortable-element-how-to-update/103258>\
**Category:** Rails\
**Created:** [May 3, 2007, 2:56pm UTC](https://www.ruby-forum.com/t/update-element-function-sortable-element-how-to-update/103258 "2007-05-03T14:56:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![22marine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/3ab097/32.png) [@22marine](https://www.ruby-forum.com/u/22marine)\
**Post date:** [May 3, 2007, 2:56pm UTC](https://www.ruby-forum.com/t/update-element-function-sortable-element-how-to-update/103258/1 "2007-05-03T14:56:24Z")

</div>

Hi.

I’ve realised this example and it works great :  
[http://demo.script.aculo.us/ajax/sortable\_elements](http://demo.script.aculo.us/ajax/sortable_elements)

But i want to add to the user the capability to add items to the  
sortable list.

Here is my code :

#######################  
#list\_controller.rb :  
#######################

class ListController \< ApplicationController  
def index  
@elements = [“toto”, “titi”, “tata”, “riri”, “fifi”, “loulou”]  
end

def order  
@order = params[:list]  
render :partial =\> ‘list’  
end  
end

#######################  
#index.rhtml :  
#######################

\<% i = 7 %\> \<% @elements.each do |elt| %\> \<span id="\<%= elt %\>" onclick="\<%= update\_element\_function('list', :position =\> :bottom, :content =\> "- #{elt}
") %\>"\> \<%= elt %\> \<% i += 1 %\> \<% end %\>

 \<% 6.times do |i| -%\> - I'm number \<%= i+1 %\>
 \<% end -%\>

\<%= sortable\_element ‘list’,  
:update =\> ‘list-info’,  
:complete =\> visual\_effect(:highlight, ‘list’),  
:url =\> { :action =\> “order” } %\>

#######################  
#\_list.rhtml  
#######################

Updated order is: \<%= @order.join(', ') %\>.

The trouble is that added elements couldn’t be sorted. Is there a way to  
“refresh” the sortable\_element method please ?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![22marine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/3ab097/32.png) [@22marine](https://www.ruby-forum.com/u/22marine)\
**Post date:** [May 3, 2007, 4:45pm UTC](https://www.ruby-forum.com/t/update-element-function-sortable-element-how-to-update/103258/2 "2007-05-03T16:45:47Z")

</div>

What I would do is on your index.rhtml page, add a remote\_form\_for  
that takes in a new element and submits it to a “add\_element” action  
in your controller. The, via an RJS file or just inline in the  
controller (via render :update) I’d replace\_html on the dom element  
that holds your list.

Curtis E.  
[http://www.okwithfailure.com](http://www.okwithfailure.com)

On May 3, 5:56 am, Titou T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![22marine](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/3ab097/32.png) [@22marine](https://www.ruby-forum.com/u/22marine)\
**Post date:** [May 3, 2007, 5:39pm UTC](https://www.ruby-forum.com/t/update-element-function-sortable-element-how-to-update/103258/3 "2007-05-03T17:39:31Z")

</div>

Curtis E. wrote […]

Thanks a lot 🙂

i wanted to avoid server requests, but i think i’ll do as you said, i’ve  
not found any other solution 😉
