Brendon Muir
2006-Jul-17 00:09 UTC
[Rails] sortable_element - Altering defaults set by rails
Hi there, I''ve got the following code to generate two sortable elements
but whenever someone drags and drops an item, i only want it to return a
serialised list of the items in categoryartworks, the unlinkedartworks
can be in any order and I don''t care. I can then delete those artworks
that were in category artworks but aren''t in the serialised list, plus
reorder the category artworks. Here''s the code:
<%= sortable_element ''categoryartworks'',
:dropOnEmpty => true,
:containment =>
["categoryartworks","unlinkedartworks"],
:constraint => false,
:parameters =>
"Sortable.serialize(\"categoryartworks\")",
:url => { :action => "order",
:category => @category.id,
}
%>
<%= sortable_element ''unlinkedartworks'',
:dropOnEmpty => true,
:containment =>
["categoryartworks","unlinkedartworks"],
:constraint => false,
:parameters =>
"Sortable.serialize(\"categoryartworks\")",
:url => { :action => "order",
:category => @category.id,
}
%>
The trouble is that rails generates this (repeats the parameters):
<script type="text/javascript">
//<![CDATA[
Sortable.create("categoryartworks", {constraint:false,
containment:[''categoryartworks'',''unlinkedartworks''],
dropOnEmpty:true,
onUpdate:function(){new
Ajax.Request(''/admin/category/1/order?category=5'',
{asynchronous:true,
evalScripts:true,
parameters:Sortable.serialize("categoryartworks")})},
parameters:Sortable.serialize("categoryartworks")})
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
Sortable.create("unlinkedartworks", {constraint:false,
containment:[''categoryartworks'',''unlinkedartworks''],
dropOnEmpty:true,
onUpdate:function(){new
Ajax.Request(''/admin/category/1/order?category=5'',
{asynchronous:true,
evalScripts:true,
parameters:Sortable.serialize("unlinkedartworks")})},
parameters:Sortable.serialize("categoryartworks")})
//]]>
</script>
-----
I want to override the default rails entry there and replace it with my
call to Sortable.serialise, right now It''s displaying both of them
which
breaks the app.
I know this is probably just a basic syntax issue but how do I get it
done?
Cheers,
Brendon Muir
--
Posted via http://www.ruby-forum.com/.
Brendon Muir
2006-Jul-17 05:31 UTC
[Rails] Re: sortable_element - Altering defaults set by rails
To answer my own question (After much searching through poor
documentation, use this:
:with => "Sortable.serialize(\"categoryartworks\")"
as in:
<%= sortable_element ''unlinkedartworks'',
:dropOnEmpty => true,
:containment =>
["categoryartworks","unlinkedartworks"],
:constraint => false,
:url => { :action => "order",
:category => @category.id
},
:with => "Sortable.serialize(\"categoryartworks\")"
%>
Cher!
Brendon
Brendon Muir wrote:> Hi there, I''ve got the following code to generate two sortable
elements
> but whenever someone drags and drops an item, i only want it to return a
> serialised list of the items in categoryartworks, the unlinkedartworks
> can be in any order and I don''t care. I can then delete those
artworks
> that were in category artworks but aren''t in the serialised list,
plus
> reorder the category artworks. Here''s the code:
>
> <%= sortable_element ''categoryartworks'',
> :dropOnEmpty => true,
> :containment =>
["categoryartworks","unlinkedartworks"],
> :constraint => false,
> :parameters =>
"Sortable.serialize(\"categoryartworks\")",
> :url => { :action => "order",
> :category => @category.id,
> }
>
> %>
>
> <%= sortable_element ''unlinkedartworks'',
> :dropOnEmpty => true,
> :containment =>
["categoryartworks","unlinkedartworks"],
> :constraint => false,
> :parameters =>
"Sortable.serialize(\"categoryartworks\")",
> :url => { :action => "order",
> :category => @category.id,
> }
>
> %>
>
> The trouble is that rails generates this (repeats the parameters):
>
> <script type="text/javascript">
> //<![CDATA[
> Sortable.create("categoryartworks", {constraint:false,
>
containment:[''categoryartworks'',''unlinkedartworks''],
dropOnEmpty:true,
> onUpdate:function(){new
> Ajax.Request(''/admin/category/1/order?category=5'',
{asynchronous:true,
> evalScripts:true,
parameters:Sortable.serialize("categoryartworks")})},
> parameters:Sortable.serialize("categoryartworks")})
> //]]>
> </script>
>
> <script type="text/javascript">
> //<![CDATA[
> Sortable.create("unlinkedartworks", {constraint:false,
>
containment:[''categoryartworks'',''unlinkedartworks''],
dropOnEmpty:true,
> onUpdate:function(){new
> Ajax.Request(''/admin/category/1/order?category=5'',
{asynchronous:true,
> evalScripts:true,
parameters:Sortable.serialize("unlinkedartworks")})},
> parameters:Sortable.serialize("categoryartworks")})
> //]]>
> </script>
>
>
> -----
>
> I want to override the default rails entry there and replace it with my
> call to Sortable.serialise, right now It''s displaying both of them
which
> breaks the app.
>
> I know this is probably just a basic syntax issue but how do I get it
> done?
>
> Cheers,
>
> Brendon Muir
--
Posted via http://www.ruby-forum.com/.