Tuesday, August 1, 2006

Simply Restful in Rails Edge

Posted by rick

David committed the simply_restful plugin to the rails this afternoon, ensuring its inclusion with the next release of Rails. Beware, there are a few API changes from the plugin, and a nice new feature:

map.resource :post
map.resource :comment, :path_prefix => '/posts/:post_id'
map.resource :trackback, :path_prefix => '/posts/:post_id'

map.resources :posts do |posts|
  posts.resources :comments, :trackbacks

Nesting the resource blocks will automatically set the path prefix from the parent’s path.

There may be some bugs introduced in the move from plugin to core, so try upgrading (and remember to remove the plugin!) and let us know if you find anything. I have the current version running on a couple apps now, so things should be working.

Update: There is one more restriction I forgot to mention. The _method hack only works on POST methods now. It is no longer valid to link to a URL like /articles/1?method=delete. Let’s not open that can of wormsvengeance.php again.

Tip #1: Use my routing navigator plugin to get a handle on what routes are being created.

Tip #2: Use the new *_path routes if you want your routes to have just the path (‘/articles/1’) instead of the whole url with protocal and host.