Method: ActionView::Helpers::JavaScriptHelper#sortable_element
- Defined in:
- lib/action_view/helpers/javascript_helper.rb
#sortable_element(element_id, options = {}) ⇒ Object
Makes the element with the DOM ID specified by element_id sortable by drag-and-drop and make an AJAX call whenever the sort order has changed. By default, the action called gets the serialized sortable element as parameters.
This method requires the inclusion of the script.aculo.us JavaScript library.
Example:
<%= sortable_element("my_list", :url => { :action => "order" }) %>
In the example, the action gets a “my_list” array parameter containing the values of the ids of elements the sortable consists of, in the current order.
You can change the behaviour with various options, see script.aculo.us for more documentation.
399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/action_view/helpers/javascript_helper.rb', line 399 def sortable_element(element_id, = {}) [:with] ||= "Sortable.serialize('#{element_id}')" [:onUpdate] ||= "function(){" + remote_function() + "}" .delete_if { |key, value| AJAX_OPTIONS.include?(key) } [:tag, :overlap, :constraint, :handle].each do |option| [option] = "'#{[option]}'" if [option] end [:containment] = array_or_string_for_javascript([:containment]) if [:containment] [:only] = array_or_string_for_javascript([:only]) if [:only] javascript_tag("Sortable.create('#{element_id}', #{()})") end |