Ruby on Rails 拖放功能不起作用
我正在尝试使用集成的脚本拖放效果创建一个 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
当我将项目放置在目标中时,放置的内容会粘在目标上。 如果目标没有“抓住”该物品,它将恢复到原来的位置。 我不明白为什么控制器中的代码没有执行。
预先感谢您的帮助
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
控制器中的代码可能已被执行。问题是它会将 ajax 请求重定向到新的 url 而不是浏览器。
您需要将 JavaScript 重定向添加到
:complete
选项。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.