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

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

问题描述

在 Rails 中的动词有问题...

查看资源(狗)的页面,其中有很多(跳蚤).嵌入在 dog 的 show.html.haml 中的是对 render @dog.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屋!

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