I am trying drag and drop in RoR for the first time.
What I want to achieve, is a list of slots, and a list of entries. You should be able to drag an entry onto a slot and slot.entry_id will update to match the dragged entry.entry_id.
I've spent a lot of time looking in textbooks and online, but cannot get the drop_receiving_element to fire. When I release an item over the slot, the item simply reverts. If someone could look through the code I've pasted and gave a hint I would appreciate it.
1. Here is the VIEW for the page:
<% f.fields_for :slots do |builder| %> <% element_to_drop_id = "slot" %> <div id="slot" > <%= builder.label :slot_number, "Slot Num" %> <%= builder.text_field :slot_number %> <%= builder.label :entry_id, "Entry Num" %> <%= builder.text_field :entry_id %> </div> <%= drop_receiving_element("slot", :accept => "entry", :hoverclass => 'hover', :with => "'entry=' + (element.id.split('_').last())", :slot_id => :slot_id, :url => {:action => :set_entry} ) %>
<% end %>
<div id="entry_list_to_move"> <%= render :partial => "entry_list_for_drag" %> </div>
2. Here is the partial entry_list_for_drag
<% @entries.each do |entry| -%> <% element_to_drag_id = "entry_#{entry.id}" %> <div class="entry" id=<%= element_to_drag_id %> style="cursor:move"> <p> <%= entry.title %> <%= entry.body %> </p> </div> <%= draggable_element(element_to_drag_id, :revert => true) %> <% end %>
3. Entries and slots exist on pages. In the page controller I'm starting to set up the below but I can't even get this to trigger
def set_entry @slot = Slot.find(params[:slot_id]) entry_id = params[:entry] @slot.entry_id = entry_id end