Rails 3 link_to(:method =>:delete)不起作用 [英] Rails 3 link_to (:method => :delete) not working
问题描述
我在Rails中的动词有问题 ...
I'm having trouble with my verbs in Rails...
正在查看页面上具有has_many(跳蚤)。嵌入狗的 show.html.haml
中是对 render @ dog.fleas
的调用,该函数会自动(?)查找并删除;使用 fleas / _flea.html.haml中的模板列出与该狗相关的每条跳蚤。
viewing a page for a resource (Dog) which has_many (Fleas). Embedded in dog's show.html.haml
is a call to render @dog.fleas
which automatically(?) finds & uses the template in "fleas/_flea.html.haml" to list each flea associated with said dog.
此显示正确。 !现在,在每条跳蚤的旁边,我都放置了一个指向URL的杀死跳蚤链接: // localhost:3000 / dogs / 1 / fleas / 7
。它是由
this displays correctly. whew! Now, next to each flea I've put a "Kill Flea" link that goes to a url: //localhost:3000/dogs/1/fleas/7
. Which is generated by:
= link_to("Kill Flea", [ flea.dog, flea ], :method => :delete, :confirm => "Sure? A bunny will die")
但每次单击链接没有任何确认...,它会显示跳蚤的 show.html
页面。好像是在 / dogs / 1 / fleas / 7
上使用 GET 而不是 Delete ?!?
but every time that link is clicked there is no confirmation... and it renders the flea's show.html
page. it's as if it's using GET on /dogs/1/fleas/7
instead of DELETE?!?
ps-不担心蜘蛛&机器人正在删除我数据库中的内容...我只是想学习Rails ..并了解发生了什么
推荐答案
Rails 3现在使用兼容的JavaScript。在Rails 2.3中,erb只会在onClick事件中将所有凌乱的javascript直接推入链接本身。现在,javascript已从链接中移出,并移至外部js文件中。确保您的布局中有此
Rails 3 uses unobtrusive javascript now. In Rails 2.3, erb would just shove all that messy javascript right into the link itself, in an onClick event. Now the javascript has been moved out of the link, and into external js files. Make sure you have this in your layout:
<%= javascript_include_tag :all %>
如果您确实有此问题,则可能会导致更深层的问题阻止JavaScript正常运行,但这是开始的地方。让我知道结果如何。
If you do have this, there might be deeper problems keeping your javascript from running, but this is the place to start. Let me know how it turns out.
这篇关于Rails 3 link_to(:method =>:delete)不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!