Update_element_function + sortable_element = how to update?

Hi.

I’ve realised this example and it works great :
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.

    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

    On May 3, 5:56 am, Titou T. [email protected]

    Curtis E. wrote […]

    Thanks a lot :slight_smile:

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