I was busy converting an old app to Rails 3 today and I ran into some problems with Prototype and the new UJS stuff in Rails 3. I set up a link_to with method delete like so:
= link_to "Delete", widget, :confirm=>"Are you sure you want to delete?", :method=>"delete"
With the new UJS setup in Rails 3, the link_to helper will create a tag like this when you use confirm and method delete:
<a rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete?" href="/widgets/123">Delete</a>
The new rails javascript file takes these parameters and uses Prototype to show you the confirm alert box and also makes it RESTful by using the DELETE method. I was a bit perplexed when I did not see the alert box and this link used the GET method instead of DELETE. I took a look at my error console in Firefox and got this error:
document.on is not a function
What the crap?? So I proceeded over to /public/javascripts/rails.js to see what was going on. They bind the click event for the <a> using the following code:
document.on("click", "a[data-method]", function(event, element) {
if (event.stopped) return;
handleMethod(element);
event.stop();
});
Apparently this does not work with the stable version of Prototype. It does work with Prototype 1.7, but I like the google hosted javascript files, and they use the stable version of 1.6. So I began questioning why one of my other apps was working just fine. Turns out that rails.js was changed with Rails 3 official release and I was using the betas for my other app. So I just took the old rails.js file from my other app and put it in this app. Here is an old version of rails.js on github
You could also upgrade to the 1.7 release candidate and use the newer rails.js file that ships with Rails 3 official, but I will stick with the Google hosted prototype. Hopefully this does not break anything else in my app



