github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

methodmissing / routing_with_optional_formats

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 13
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Selectively enable or disable formatted named routes being generated — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

cleanups 
methodmissing (author)
Wed Sep 10 10:00:16 -0700 2008
commit  a9fe110c8ffc90a97ce73d8dc3efb86b9a681ea1
tree    90d3b8ca33449f249ca4b0a944f8d2a0819deaa6
parent  5ba34652ce8467a029057eac0701272d80cee29a
routing_with_optional_formats /
name age
history
message
file .gitignore Loading commit data...
file MIT-LICENSE
file README.textile
file Rakefile Fri Jul 11 05:41:41 -0700 2008 initial [methodmissing]
file init.rb
file install.rb
directory lib/
directory tasks/
directory test/
file uninstall.rb Fri Jul 11 05:41:41 -0700 2008 initial [methodmissing]
README.textile

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

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server