# Ajax sortable\_element refresh

**URL:** <https://www.ruby-forum.com/t/ajax-sortable-element-refresh/105349>\
**Category:** Rails\
**Created:** [May 29, 2007, 6:36am UTC](https://www.ruby-forum.com/t/ajax-sortable-element-refresh/105349 "2007-05-29T06:36:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hpacheco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/dfb087/32.png) [@hpacheco](https://www.ruby-forum.com/u/hpacheco)\
**Post date:** [May 29, 2007, 6:36am UTC](https://www.ruby-forum.com/t/ajax-sortable-element-refresh/105349/1 "2007-05-29T06:36:47Z")

</div>

Hi,

I have the following ajax example, with a list of counters, and two  
buttons for adding/removing elements. The list is sortable.

There are two things that I don’t know how to do:  
. remove an elemet  
. when I add a new element to the list, that element doesn’t become  
sortable with the rest of the list

Thanks,  
hugo

#### View
 Ajax List Demo \<%= javascript\_include\_tag :defaults %\> \<%= form\_remote\_tag(:update =\> "list", :url =\> { :action =\> :add\_item }, :position =\> "bottom" ) %\>

```
  <%= text_field_tag :newitem %>
  <%= submit_tag "Add item" %>
<%= end_form_tag %>

```

\<%= form\_remote\_tag(:delete =\> “list”,  
:url =\> { :action =\> :cyaitem }) %\>

```
  <%= text_field_tag :cyaitem %>
  <%= submit_tag "Remove item" %>
<%= end_form_tag %>

```

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

\<%= sortable\_element ‘list’, :complete =\> visual\_effect(:highlight,  
‘list’) %\>

### Controller

def index  
end

def add\_item  
render\_text “\<li id=“item\_7” + “”\>I’m number 7”  
end
