Forum: Ruby on Rails Drag and Drop to multiple, dynamic lists

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.
B8450093425b4a8b2c2c888671418245?d=identicon&s=25 Dcjgoose (Guest)
on 2007-02-20 23:28
(Received via mailing list)
Hello,

I am attempting to create an admin tool so that admins can drag and
drop "users" to add them to a "group". Once I have dropped the users
into the group element, I want to update my group_users table which is
HABTM.

So far, I have properly created a draggable element for each user:

<%= draggable_element "#{user.id}", :revert => true  %>

I am also using the drop_receiving_element for each group (properly
accessed "add" when item is dropped)
<%= drop_receiving_element "group#{group.id}",
:url => { :action => "add"},
:accept => "users",
:loading => "Element.show('indicator')",
:complete => "Element.hide('indicator')" %>

What I need to also pass is the group.id so that I can update the
group_users table upon drop. In all the documentation I've read about
scriptaculous drag-and-drop & drag-and-drop sortable-lists, nothing is
explained about the options you can pass to the drop_receiving_element
tag.

Has anyone implemented this with dynamic lists?

Thanks!
-Dina
B8450093425b4a8b2c2c888671418245?d=identicon&s=25 Dcjgoose (Guest)
on 2007-02-21 01:04
(Received via mailing list)
I have finally found a solution:

You can set additional params in the url so my drop_receiving element
tag is now:

<%= drop_receiving_element "group#{group.id}",
:url => { :action => "add", :group_id => "#{group.id}" },
:accept => "users",
:loading => "Element.show('indicator')",
:complete => "Element.hide('indicator')" %>

The user id from the draggable element is automatically set for
params[:id]. To update params[:id] you would use the :with option in
the drop_receiving_element...not what I wanted since I need both group
id and user id for my join table.

Hope this helps anyone working on anything similar.
-Dina
This topic is locked and can not be replied to.