Rails 3 link_to (:method => :delete) 不工作 [英] Rails 3 link_to (:method => :delete) not working

查看:14
本文介绍了Rails 3 link_to (:method => :delete) 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Rails 中遇到了动词问题...

I'm having trouble with my verbs in Rails...

查看具有许多(跳蚤)的资源(狗)的页面.嵌入在狗的 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 =&gt; :delete) 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆