Ensuring Graceful Degradation
To implement a fallback action for browsers that don’t support Ajax, we actually just need to take care of the different treatment for browsers with and without Javascript support on the behalf of the create action of VotesController, since the HTML generated by the form_remote_tag helper we’ve used to generate our voting form is already fully compatible with both worlds.
Our plan is to redirect users back to the story page after we’ve processed their votes with their non-Javascript browsers while users with Ajax-enabled browsers can watch as the total number of votes is updated and highlighted without a page reload. To instruct our votes controller to take appropriate action, whether it’s dealing with
an Ajax request or a regular HTTP POSTrequest, we need to modify the createaction in our VotesController class like so:
Bookmarks