Skip to content

methodmissing/routing_with_optional_formats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Selectively enable or disable formatted named routes being generated

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages