watch this  

the official mrchucho blog

The REST is History

Posted 2008 Feb 14

It’s all about the Rewrite Condition.

Rails page caching is great and REST is great, but together they can be confusing. Considering a resource “Posts”, Rails gives you the following routes:

  GET    /posts     {:controller=>"posts", :action=>"index"}
 POST    /posts     {:controller=>"posts", :action=>"create"}
  PUT    /posts/:id {:controller=>"posts", :action=>"update"}

If you have Apache configured with mod_rewrite to serve your cached pages (instead of sending them to mongrel, e.g.), then all of those routes appear to be requests for “posts.html”. The end result is that you can’t create or update the “Posts” resource. The solution, let Apache handle the GET requests and mongrel handle everything else:

RewriteEngine On
RewriteRule ^/$ /index.html [QSA]

RewriteRule ^([^.]+)$ $1.html [QSA]

RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]

Responses to "The REST is History"

No responses yet.

Comments are now closed.
atom rss