We all know that we should do POST requests whenever in our application we trigger a "destructive" action. This beacause it is the appropriate HTTP verb and 'cause search engine/spider/crawlers won't follow/trigger this POST links or html form buttons. Rails has the button_to helper to generate a form with just a single submit element to use as a POST link. We can also use a normal link_to helper to generate a normal <a> link element and then with a parameter to that helper method we can turn that link default behaviour from GET to POST. Now i wonder what is the best method to implement a POST request in a rails application. In particular i would like to know if it is better to use normal <a> elements (with javascript to turn that link request from GET to POST with the help of rails helper) instead of buttons (button_to helper), and this from a usability/accessibility perspective.
For the most common use case of Delete links, it is perfectly possible to use a link instead of a button and maintain the use of POST (well, DELETE in an ideal world) using Javascript but keep things accessible for those not using Javascript.
I would have it so that the link by default (no js) links to an intermediate confirmation page ("are you sure you want to delete this?") with a form and a button to finalise the delete. You would then augment this link using JS to capture the same functionality only on the same page (an alert box provides the confirm dialog then AJAX fires off the delete request).
Bookmarks