Rails 3 :method=> :delete doesn't work in Internet Explorer

前端 未结 11 859
天涯浪人
天涯浪人 2020-12-09 00:44

I am going through the rails 3 tutorial at railstutorial.org. I have just created an extremely simple scaffold Users.

The scaffold-generated destroy link does not wo

相关标签:
11条回答
  • 2020-12-09 00:46

    By default, new rails projects are created with Prototype javascript libraries, with some prototype-specific helper functions in "public/javascript/rails.js". The scaffolding relies on some of these helpers to handle some things, like destroying a record, since there isn't a good javascript-free way of making a DELETE request, etc.

    Make sure that your pages are loading both the javascript libraries and the "rails.js" file, which are needed to make the scaffolding work (see theschmitzer's answer, or check in Firebug).

    Second, if you are using jQuery, install the 'jquery-rails' gem and then run "rails g jquery:install". This will remove the Prototype libraries, install the jQuery libraries, and update the helpers to use jQuery.

    0 讨论(0)
  • 2020-12-09 00:52

    Replace public/javascripts/rails.js of your application with this one:

    https://github.com/rails/prototype-ujs/raw/master/src/rails.js

    This is updated recently (2010/11/13).

    The rails.js bundled with Rails 3.0.0/3.0.1 does not work well on Internet Explorer.

    0 讨论(0)
  • 2020-12-09 00:52

    This is probably because the loading of your script (rails.js and/or application.js) happens in head. At script execution time, there are no elements in your DOM with the attributes data-confirm and data-method.

    So, the solution is to move the javascript tag to the end of <body>. At this time, the DOM has most likely been loaded and the javascript will find your elements.

    0 讨论(0)
  • 2020-12-09 00:53

    You need to upgrade your prototype distribution to 1.7 instead of 1.7rc2 (which doesn't have full support for IE 9). The latest Rails gem (at time of writing( in the gem repo is bundling 1.7rc2. Go to the prototype homepage, download the new 1.7 release and replace this with the bundled prototype.js.

    0 讨论(0)
  • 2020-12-09 00:57

    I couldn't get it to work with IE9 with the default javascript libraries, so I installed jquery-rails and it works just fine. Not perhaps the ideal solution, but if it works...

    0 讨论(0)
  • 2020-12-09 01:02

    Make sure you have <%= javascript_include_tag :defaults %>

    JS is now unobtrusive in rails 3, so the include is required to make it work.

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