views:

458

answers:

1

Hi,

I am trying to create a Ruby on rails application using the integrated scriptaculous drag and drop effect.

Since I'm new to the ruby language I ended up with this code while viewing many documentation but can't understand why the controller code is not executed.

In the html.erb page the origin div

   <% for therm in @therms %>
   <tr valign="top" class="<%= cycle('list-line-odd', 'list-line-even') %>">

  <td>
  <% therm_id = "therm_#{therm.id}" %>
  <li class="origin" id='<%= therm_id %>'><%= therm.id %></li>
  </td>

The target

<%= image_tag "dragtrash.png", :id=>'trash'%>

And I identify the drop target

<%= drop_receiving_element('trash',
:accept => 'origin',
:complete => "$('spinner').hide();" ,
:before => "$('spinner').show();" ,
:hoverclass => 'hover',
:with => "'paramid=' + encodeURIComponent(element.id.split('_').last())" ,
:url => {:action=>:trash_therm})%>

And finally in my controller

   def trash_therm
 redirect_to(:action => 'create')
   end

When I drop the item in the target the dropped content sticks to the target. If the target didn't "catch" the item it would revert to it's original position. I don't understand why the code in the controller is not executed.

Thank in advance for help

A: 

The code in the controller might have been executed. The problem is that it would redirect the ajax request to the new url and not the browser.

You need to add a javascript redirect to the :complete option.

window.location.href = url
BaroqueBobcat
Tried with <%= drop_receiving_element('trash', :accept => 'origin', :complete => "window.location.href = www.google.com" , :before => "$('spinner').show();" , :hoverclass => 'hover', :with => "'paramid=' + encodeURIComponent(element.id.split('_').last())" , :url => {:action=>:trash_therm})%>I think the options :complete and :before are not necessary like in the example of http://ruby.dzone.com/news/drag-drop-rails since I'm trying to have the code of the controller executed.
SilverRuby
They are not necessary if you just want the controller action to run without affecting the browser. If you want to redirect the browser, it is more complicated. Run your app with script/server and check the output when you do your drag and drop. Does it log the trash_therm action being called?
BaroqueBobcat