ruby-on-railsscriptaculous

rails sortable_element doesn't load?


I am using Rails 2.3

I have this code:

           <%=
                   sortable_element(
                           'image_list',
                           :url => { :action => update_image_rank_ajax', :id => @product.id }
                   )
           %>

which runs fine on "one admin page" but not fine on "one user page"

The code it generates, ex:

<script type="text/javascript">
//<![CDATA[
Sortable.create("image_list", {onUpdate:function(){new Ajax.Request('/admin/products/update_image_rank_ajax/5441', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("image_list") + '&authenticity_token=' + encodeURIComponent('rri641tMwhYHb+WlmGt42T5OtVQD4qvaXjWrCwGrO1A=')})}})
//]]>
</script>

If I just run that in the javascript console, it works.

So it's like it's running it too early?


Solution

  • Turns out the problem is I was loading prototype (et al) twice.

       <%= javascript_include_tag :defaults, :cache => 'default', :defer => true %>
    

    and then again later:

       <%= javascript_include_tag 'effects', 'dragdrop', 'controls' %>
    

    My hunch is it was somehow confusing between the javascript libraries being loaded twice, removing the :defaults one fixed it, at any rate.