Ruby on Rails拖放将无法正常工作

时间:2009-10-09 18:52:51

标签: ruby-on-rails drag-and-drop scriptaculous

我正在尝试使用集成的scriptaculous拖放效果创建一个Ruby on rails应用程序。

由于我是ruby语言的新手,因此在查看许多文档时我最终得到了这段代码,但却无法理解为什么控制器代码没有被执行。

在html.erb页面中,原点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>

目标

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

我确定掉落目标

<%= 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})%>

最后在我的控制器中

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

当我将物品放入目标时,掉落的内容会粘在目标上。 如果目标没有“捕获”该项目,它将恢复到它的原始位置。 我不明白为什么控制器中的代码没有被执行。

提前感谢您的帮助

1 个答案:

答案 0 :(得分:0)

控制器中的代码可能已被执行。问题是它会将ajax请求重定向到新的URL而不是浏览器。

您需要将javascript重定向添加到:complete选项。

window.location.href = url