Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
One rule for complete restful routing, no helpers, no worries.
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
benchmark
lib
spec
README.markdown
Rakefile
init.rb

README.markdown

map.resources :user
map.resources :products, :member => {:goto => :get, :bar => :get}
map.resources :ads, :collection => {:search => :get, :preview => :get}
map.resources :lists, :member => {:something => :post}
map.resources :toys, :collection => {:foo => :put}
map.resources :sounds
...
map.restful_catch_all_route

(For Rails 2 and 3)

  • REST like normal (/users <-> index+create, /users/1 <-> show+update+destroy, /users/1/edit, /users/new )
  • collection and members map automatically (/users/search, /users/1/add)
  • _url / _path / _hash helper free global namespace
  • fallback to map.resources for e.g. nested resources
  • restful catch all route example app

Install

script/plugins install git://github.com/grosser/restful_catch_all_route.git

# config/routes.rb
map.restful_catch_all_route

namespace(:admin) do |admin|
  admin.restful_catch_all_route  
end

# if you need REST-less fallback urls, they must be placed after restful catch all
# map.connect ':controller/:action/:id'

Usage

# like normal:
url_for(@user) <-> show
url_for(User) <-> index
url_for([:admin, @user]) <-> with namespace
...
form_for @user
link_to 'hey', @user
polymorphic_url(@user)

# instead of edit_user_path(user):
"/users/edit/#{user.id}"
url_for(user)+'/edit'
polymorphic_url(user, :action => :edit)
:controller => :users, :action => :edit, :id => user.id

Id formats

By default it accepts ids that are pure numbers, or contain a '-'.
You can overwrite it by passing :id => /my_rex/

  • /my_controller/1/edit - works
  • /my_controller/1-fancy-title/edit - works
  • /my_controller/fancy-title/edit - works
  • /my_controller/fancy_title/edit - works NOT

Performance

Rails 2.3.5 with 50 resources 100_000 times

Recognition Generation RAM Helpers
catch all 9.1s 6.6 200+ (1
resources 68.2s 9.5 +9MB 0

(1 50 * (xxx_path + xxxs_path + new_xxx_path + edit_xxx_path + custom members)

Author

Michael Grosser
grosser.michael@gmail.com
Hereby placed under public domain, do what you want, just do not hold me accountable...

Something went wrong with that request. Please try again.