Rails 3.1 link_to not showing confirmation or destroying properly

被刻印的时光 ゝ 提交于 2019-12-01 18:48:31
flipside

So for all of you pulling out your hair for using Rails 3.1, here's the solution.

<%= javascript_include_tag "application" %>

Using "application" instead of :defaults solves this problem, delete and confirm should work, now get back to coding!

Special thanks to George Shaw for this answer over on https://stackoverflow.com/a/8350158/1127011 .

And it case you were wondering, title is for mouseover only.

The a HTML tag will always fire the GET method. Rails uses the Javascript driver to replace the HTTP verb. The link_to method will fallback any method (post, put and delete) to get (corresponding to the show action) when :

  • Javascript has been disabled by the user
  • for some reason, Rails unobtrusive javascript driver is not handling the link properly

See http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html

I suspect the second reason to be the issue. Make sure the jquery.js, application.js, jquery_ujs.js file are included.

Instead of link_to, you could try to use button_to which creates a form allowing put, post and delete methods without Javascript enabled.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!