开发者

Ruby on Rails drag and drop won't work

开发者 https://www.devze.com 2022-12-08 17:45 出处:网络
I am trying to create a Ruby on rails application using the integrated scriptaculous drag and drop effect.

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 i开发者_StackOverflow中文版t's original position. I don't understand why the code in the controller is not executed.

Thank in advance for help


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
0

精彩评论

暂无评论...
验证码 换一张
取 消