Friday, April 24, 2009

Redirecting a database update using Rails

I learned a handy trick today.

Rails contains a convenience method that allows you to redirect page requests (or submissions) called "redirect_to". Rails also contains a submission method called "PUT" in addition to the "GET" and "POST" supported by HTTP.

When you want to update a record in the database, the technique for doing so is to establish that the submission type of the update method is a "PUT". However, if you want to create a delegate method in between the submission and the actual deed, you need to "POST" to your delegate method then have that method send it's redirection using "PUT".

This is *not obvious* and the solution is best explained by this blog. I've tried it and it works.

No comments:

Post a Comment