Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Merb::Router.prepare do |r|
- r.resources :posts
- r.default_routes
- r.match('/').to(:controller => 'whatever', :action =>'index')
- end
- will produce this match method:
- def match(request)
- params = request.params
- cached_path = request.path
- cached_method = request.method.to_s
- if # {:path=>"^/posts/?(\\.:format)?$", :method=>"^get$"}
- (/^\/posts\/?(\.([^\/.,;?]+))?$/ =~ cached_path) && (path1, path2 = $1, $2) && (/^get$/ =~ cached_method)
- # then
- [0, {:action => "index", :format => path2, :controller => "posts"}]
- elsif # {:path=>"^/posts/index(\\.:format)?$", :method=>"^get$"}
- (/^\/posts\/index(\.([^\/.,;?]+))?$/ =~ cached_path) && (path1, path2 = $1, $2) && (/^get$/ =~ cached_method)
- # then
- [1, {:action => "index", :format => path2, :controller => "posts"}]
- elsif # {:path=>"^/posts/new$", :method=>"^get$"}
- (/^\/posts\/new$/ =~ cached_path) && (/^get$/ =~ cached_method)
- # then
- [2, {:action => "new", :controller => "posts"}]
- elsif # {:path=>"^/posts/?(\\.:format)?$", :method=>"^post$"}
- (/^\/posts\/?(\.([^\/.,;?]+))?$/ =~ cached_path) && (path1, path2 = $1, $2) && (/^post$/ =~ cached_method)
- # then
- [3, {:action => "create", :format => path2, :controller => "posts"}]
- elsif # {:path=>"^/posts/:id(\\.:format)?$", :method=>"^get$"}
- (/^\/posts\/([^\/.,;?]+)(\.([^\/.,;?]+))?$/ =~ cached_path) && (path1, path2, path3 = $1, $2, $3) && (/^get$/ =~ cached_method)
- # then
- [4, {:action => "show", :format => path3, :controller => "posts", :id => path1}]
- elsif # {:path=>"^/posts/:id[;/]edit$", :method=>"^get$"}
- (/^\/posts\/([^\/.,;?]+)[;\/]edit$/ =~ cached_path) && (path1 = $1) && (/^get$/ =~ cached_method)
- # then
- [5, {:action => "edit", :controller => "posts", :id => path1}]
- elsif # {:path=>"^/posts/:id[;/]delete$", :method=>"^get$"}
- (/^\/posts\/([^\/.,;?]+)[;\/]delete$/ =~ cached_path) && (path1 = $1) && (/^get$/ =~ cached_method)
- # then
- [6, {:action => "delete", :controller => "posts", :id => path1}]
- elsif # {:path=>"^/posts/:id(\\.:format)?$", :method=>"^put$"}
- (/^\/posts\/([^\/.,;?]+)(\.([^\/.,;?]+))?$/ =~ cached_path) && (path1, path2, path3 = $1, $2, $3) && (/^put$/ =~ cached_method)
- # then
- [7, {:action => "update", :format => path3, :controller => "posts", :id => path1}]
- elsif # {:path=>"^/posts/:id(\\.:format)?$", :method=>"^delete$"}
- (/^\/posts\/([^\/.,;?]+)(\.([^\/.,;?]+))?$/ =~ cached_path) && (path1, path2, path3 = $1, $2, $3) && (/^delete$/ =~ cached_method)
- # then
- [8, {:action => "destroy", :format => path3, :controller => "posts", :id => path1}]
- elsif # {:path=>"/:controller(/:action(/:id)?)?(\\.:format)?"}
- (/\/([^\/.,;?]+)(\/([^\/.,;?]+)(\/([^\/.,;?]+))?)?(\.([^\/.,;?]+))?/ =~ cached_path) && (path1, path2, path3, path4, path5, path6, path7 = $1, $2, $3, $4, $5, $6, $7)
- # then
- [9, {:action => path3 || "index", :format => path7, :controller => path1, :id => path5}]
- elsif # {:path=>"^/$"}
- (/^\/$/ =~ cached_path)
- # then
- [10, {:action => "index", :controller => "whatever"}]
- else
- [nil, {}]
- end
- end
Add Comment
Please, Sign In to add comment