Forum: Ruby on Rails how to create an association through a Drag & Drop

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.
662234d1d667d032cd7835095c789e25?d=identicon&s=25 Sacredceltic (Guest)
on 2009-03-17 16:29
(Received via mailing list)
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 :

<ul id="A_list">
  <% for A in @As %>
  <% draggableA_id = "draggableA_#{A.id}" %>
  <li id=<%= draggableA_id %> class="draggableAs">
     <% A.name %>
        </li>
        <%= draggable_element(draggableA_id, :revert=>true) %>
  <% end %>
</ul>

<ul id="B_list">
  <% for B in @Bs %>
       <% droppableB_id = "droppableB_#{B.id}" %>
       <li id=<%= droppableB_id %> class="droppableBs">
           <%= B.name %>
      </li>
      <%= drop_receiving_element(droppableB_id,
      :accept => "draggableAs",
      :with   => "'draggableA=' + (element.id.split('_').last())",
      :url    => {:action=>:create_C}
      )%>
  <% end %>
</ul>

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...
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-17 17:04
(Received via mailing list)
On Mar 17, 3:28 pm, Sacredceltic <sacredcel...@gmail.com> 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:
http://www.spacevatican.org/2008/5/17/with-or-with...

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

Fred
This topic is locked and can not be replied to.