Every repository with this icon (
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Tue Jul 15 19:04:31 -0700 2008 | |
| |
MIT-LICENSE | Fri Jul 11 05:41:41 -0700 2008 | |
| |
README.textile | Mon Jul 14 09:48:04 -0700 2008 | |
| |
Rakefile | Fri Jul 11 05:41:41 -0700 2008 | |
| |
init.rb | Fri Jul 11 07:32:54 -0700 2008 | |
| |
install.rb | Fri Jul 11 05:41:41 -0700 2008 | |
| |
lib/ | Wed Sep 10 10:00:16 -0700 2008 | |
| |
tasks/ | Fri Jul 11 05:41:41 -0700 2008 | |
| |
test/ | Tue Jul 15 12:21:56 -0700 2008 | |
| |
uninstall.rb | Fri Jul 11 05:41:41 -0700 2008 |
Routing with optional Formatted routes
Why ?
Each mapped resource spawns 14 named routes, as well as corresponding entries in the routing table.
- 7 default
- 7 for formatted routes
- x 2 more for each custom collection or member definition
You would typically only supported different content types over a select few resources.Having the various format friendly routes generate is rather wasteful on Memory use.
Some lean controllers may also only support a subset of the REST verbs.
class ArticlesController < ActionController::Base
def index
end
def show
end
end
Doesn’t really justify having all 7 variations defined.
This becomes quite painful with large code bases with multiple namespaces where Routing overhead can be quite significant, both in Memory use and Recognition.
Statistics
Our per process on startup Memory use used to be 177M RES ( Solaris top output ) prior to injecting this plugin.
PID USERNAME LWP PRI NICE SIZE RES STATE TIME CPU COMMAND
25895 mongrel 2 1 0 146M 136M sleep 0:48 0.07% mongrel_rails
25898 mongrel 2 1 0 146M 135M sleep 0:47 0.06% mongrel_rails
25887 mongrel 2 1 0 146M 136M sleep 0:47 0.06% mongrel_rails
25892 mongrel 2 1 0 146M 136M sleep 0:48 0.06% mongrel_rails
My Functionals appear ( sorry, no scaling or performance can of worms here ) to run 15% faster.
Where this is going …
- Ability to infer, via each Resource definition, exactly which actions is defined by the Controller.
- Catch UnknownAction errors via routes.rb
- Generating a less cluttered Routing table.
Configuration
ActionController::Base.prune_routes is set to true for Production environment by default.
For other environments, business as usual to avoid Reloading issues etc.
Example
map.resources :articles, :formatted => false do |article|
article.resources :comments
article.resources :photos, :formatted => false
end
This isn’t a typical use case, but it helps us control overall per process Memory use.
Author:: Lourens Naudé
License:: Copyright 2008 by Lourens Naudé.
Released under an MIT-style license. See the LICENSE file
included in the distribution.
GitHub:: http://github.com/methodmissing/routing_with_optional_formats/tree/master







