问题描述
我一直在浏览 railstutorial.org 上的章节并使用 Rails 3.1.3,因为我很疯狂和/或想要挑战.我设法轻松地找出了大多数版本问题,但这个问题让我难住了一段时间.
I've been plowing through the chapters at railstutorial.org and been using Rails 3.1.3 because I'm crazy and/or wanted a challenge. I managed to figure out most version problems easily but this one stumped me for a while.
在 10.4.2 中,Michael Hartl 使用以下代码删除用户:
In 10.4.2, Michael Hartl uses the following code to delete users:
<%= link_to "delete", user, :method => :delete, :confirm => "You sure?",
:title => "Delete #{user.name}" %>
如果您在浏览器 (chrome) 中对其进行测试,而是将您发送到该用户页面,则它无法正常工作.
It doesn't work properly if you test it in the browser (chrome) and instead sends you to that user page.
如果您包含此内容,它应该可以工作:
It is supposed to work if you include this:
<%= javascript_include_tag :defaults %>
但它在 Rails 3.1 上失败了(不过它应该适用于 Rails 3.0,或者我听说).
but it fails with Rails 3.1 (it should work for Rails 3.0 though, or so I hear).
推荐答案
所以对于那些为使用 Rails 3.1 感到费解的人,这里是解决方案.
So for all of you pulling out your hair for using Rails 3.1, here's the solution.
<%= javascript_include_tag "application" %>
使用application"而不是 :defaults 解决了这个问题,删除并确认应该可以工作,现在回到编码!
Using "application" instead of :defaults solves this problem, delete and confirm should work, now get back to coding!
特别感谢 George Shaw 在 https://stackoverflow.com/a/8350158/1127011 .
如果您想知道,标题仅用于鼠标悬停.
And it case you were wondering, title is for mouseover only.
这篇关于Rails 3.1 link_to 未正确显示确认或销毁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!