Rails 3.1 link_to not showing confirmation or destroying properly

后端 未结 2 744
旧巷少年郎
旧巷少年郎 2021-01-20 01:22

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 pr

相关标签:
2条回答
  • 2021-01-20 02:06

    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.

    0 讨论(0)
  • 2021-01-20 02:11

    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.

    0 讨论(0)
提交回复
热议问题