This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| name | age | message | |
|---|---|---|---|
| |
README | ||
| |
Rakefile | ||
| |
init.rb | Thu Jun 05 10:02:10 -0700 2008 | |
| |
lib/ | ||
| |
test/ | Thu Jun 05 10:21:27 -0700 2008 |
README
RoutingTricks
=============
This is a collection of hacks and tricks that may or may not actually be
useful. It is intended more as a tool for exploring (and teaching) the
internals of Rails' routing implementation.
map.redirect
------------
This is a tool for specifying a redirect from one route to another. Any
request matching the route will emit a 302 response that redirects to the
target route. It requires that the target be a named route. Consider:
ActionController::Routing::Routes.draw do |map|
map.resources :things
map.redirect "/", :things
end
By default, the map.resources command does not map anything to the root URL,
"/". We can use map.redirect to easily cause requests for "/" to be redirected to the things url, "/things".
If a route has parameters, those will be passed to the destination route as well:
ActionController::Routing::Routes.draw do |map|
map.resources :things
map.redirect "/:id", :thing
end
In this case, a request for "/15" would be redirected to "/thing/15", automatically.
Recognition based on host/domain/subdomain
------------------------------------------
This allows you to specify the host, domain, or subdomain as a condition for
recogizing the request. For instance, you can have two identical paths that
route to different controllers and actions, depending on what the subdomain
is:
ActionController::Routing::Routes.draw do |map|
map.connect "/", :controller => "admin", :conditions => { :subdomain => "admin" }
map.connect "/", :controller => "public"
end
Then, "admin.foo.com" would go to the admin controller, while "www.foo.com"
and "123.foo.com" will go to the public controller.
Similarly, you can specify :host and :domain in the conditions hash. The values can be either strings (for exact
matches) or regular expressions (for more dynamic matching).







