- The Two Purposes of Routing
- Bound Parameters
- Wildcard Components ("Receptors")
- Static Strings
- The routes.rb File
- The Ante-Default Route and respond_to
- The Empty Route
- Writing Custom Routes
- Using Static Strings
- Using Your Own "Receptors"
- A Note on Route Order
- Using Regular Expressions in Routes
- Default Parameters and the url_for Method
- Using Literal URLs
- Route Globbing
- Globbing Key-Value Pairs
- Named Routes
- What to Name Your Routes
- The Special Scope Method with_options
Using Static Strings
Keep in mind that there's no necessary correspondence between the number of fields in the pattern string, the number of bound parameters, and the fact that every connection needs a controller and an action.
For example, you could write a route like this:
map.connect ":id", :controller => "auctions", :action => "show"
which would recognize a URL like this:
The routing system would set params[:id] to 8 (based on the position of the :id "receptor," which matches the position of "8" in the URL), and it would execute the show action of the auctions controller. Of course, this is a bit of a stingy route, in terms of visual information. You might want to do something more like Listing 2.2, which is a little richer semantically-speaking:
map.connect "auctions/:id", :controller => "auctions", :action => "show"
This version of the route would recognize this:
In this route, "auctions" is a static string. It will be looked for in the URL, for recognition purposes; and it will be inserted into the URL when you generate it with the following code:
<%= link_to "Auction details", :controller => "auctions", :action => "show", :id => auction.id %>