How to create an association through a Drag & Drop

I have 3 tables A, B and C

Table A has_many Cs
Table B has_many Cs
so C contains 2 foreign keys, A_id and B_id)

I have a screen with 2 lists : A list and B list
I would like to be able to create a C record by simply dropping an A
element on a B element

I tried this :

    <% for A in @As %> <% draggableA_id = "draggableA_#{A.id}" %>
  • class="draggableAs"> <% A.name %>
  • <%= draggable_element(draggableA_id, :revert=>true) %> <% end %>
    <% for B in @Bs %> <% droppableB_id = "droppableB_#{B.id}" %>
  • class="droppableBs"> <%= B.name %>
  • <%= drop_receiving_element(droppableB_id, :accept => "draggableAs", :with => "'draggableA=' + (element.id.split('_').last())", :url => {:action=>:create_C} )%> <% end %>

It drops OK, but :

  1. The problem is, the “:with” parameter takes only one key. How do I
    convey the second one ? It doesn’t seem to accept a hash…
  2. When I debug, I see that the draggableA_id that I drop is always
    the last draggableA_id, whichever draggableA I drag…

On Mar 17, 3:28 pm, Sacredceltic [email protected] wrote:

It drops OK, but :

  1. The problem is, the “:with” parameter takes only one key. How do I
    convey the second one ? It doesn’t seem to accept a hash…

There’s some examples of the usage of :with here:

(it’s mostly about link_to_remote but that doesn’t matter)

Fred