开发者

Ruby on Rails drag and drop won't work

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜