RESTful Rails and Unobtrusive Javascript // writing
The major project I’m working on has resulted in a lot of reading. I’ve brushed up by reading Transcending CSS, DOM Scripting and reread the latest version of Agile Web Development with Rails. All of which are marvellous.
Being a fan of both the unobtrusive scripting approach and Rails means the UJS4Rails plugin is a total godsend, allowing the interactivity of AJAX without sacrificing proper behaviour separation from the underlying HTML/CSS.
However along comes REST, a new-ish and clever way to do your (Create Read Update Delete) using the power of HTTP requests to streamline your code. There is a fantastic guide to RESTful Rails Development that’s well worth a read, it’s the document that made me slap my own forehead at the obviousness of it all.
One of the key factors in the use of the REST approach in Rails is the faking of the DELETE HTTP request as modern browsers don’t use it. However this is done by using inline javascript on the link to generate a form, which is not exactly unobtrusive or accessible to those sans-JS.
I’ve posted a question to the UJS4Rails Google Group in the hope of an answer… it is a bit more well trafficked than here!
Update
The wonderful Dan Webb pointed me in the direction of button_to instead of link_to for destructive actions, which makes absolute sense and removes the need for the crazy javascript form. What a gent. You can see the slides from his RailsConf presentation for examples.