Forum: Ruby on Rails Sortable Element with Partials?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jordan I. (Guest)
on 2006-01-21 05:29
Hi Everyone,

I posted this last month and unfortunately, I didn't recieve any
replies.  Maybe this time I'll have better luck.  I originally had my
sortable element list working properly like so:

<ul id="sortable_list">
   <% @items.each do |item| %>
   <li id="item_<%= item.id %>"><%= image_tag "dragme.gif" %><span
id="title_<%= item.id %>" class="title"> <%= item.value %></span> <span
class="actions"><%= link_to("Delete", :action => "destroy", :id =>
item.id) %></span></li>

<%= sortable_element('sortable_list', :update => "list-info", :url =>
{:action => :update_positions}) %>
<% end %>
</ul>

However, now that I have added AJAX CRUD controls, I can't seem to get
the sortable elements to work!  I am using a partial within my <ul> and
I suspect that this may be part of the problem...

<ul id="sortable_list">
  <%= render(:partial => 'item', :collection => @items) %>
</ul>
<%= sortable_element('sortable_list', :update => "list-info", :url =>
{:action => :update_positions}) %>

I think it may not be getting the proper items or IDs to set them to
"sortable elements".  Does anybody have any ideas?

Thanks in advance.  By the way, I am very new to rails, please let me
know if you need anything else to help solve the problem.
Marcus V. (Guest)
on 2006-02-23 07:35
Jordan I. wrote:
> Hi Everyone,
>
> I posted this last month and unfortunately, I didn't recieve any
> replies.  Maybe this time I'll have better luck.  I originally had my
> sortable element list working properly like so:
>
> <ul id="sortable_list">
>    <% @items.each do |item| %>
>    <li id="item_<%= item.id %>"><%= image_tag "dragme.gif" %><span
> id="title_<%= item.id %>" class="title"> <%= item.value %></span> <span
> class="actions"><%= link_to("Delete", :action => "destroy", :id =>
> item.id) %></span></li>
>
> <%= sortable_element('sortable_list', :update => "list-info", :url =>
> {:action => :update_positions}) %>
> <% end %>
> </ul>
>
> However, now that I have added AJAX CRUD controls, I can't seem to get
> the sortable elements to work!  I am using a partial within my <ul> and
> I suspect that this may be part of the problem...
>
> <ul id="sortable_list">
>   <%= render(:partial => 'item', :collection => @items) %>
> </ul>
> <%= sortable_element('sortable_list', :update => "list-info", :url =>
> {:action => :update_positions}) %>
>
> I think it may not be getting the proper items or IDs to set them to
> "sortable elements".  Does anybody have any ideas?
>
> Thanks in advance.  By the way, I am very new to rails, please let me
> know if you need anything else to help solve the problem.

Jordan,
Try passing the object you're using to your partial like this:
<%= render(:partial => 'item', :collection => @items,:locals => {:item
=> item}) %>

Then when you want to modify the item use:
{ :action => 'edit_item', :id => item }
for example.

I hope that's enough to help.
This topic is locked and can not be replied to.