Default Routes
To get started with Routing, Mack gives you the option of defining 'default' routes, as shown below:
Mack::Routes.build do |r| r.defaults end
By adding r.defaults to Mack::Routes you are actually defining 8 different routes. They are as follows:
- /:controller/:action [GET]
- /:controller/:action [POST]
- /:controller/:action [PUT]
- /:controller/:action [DELETE]
- /:controller/:action/:id [GET]
- /:controller/:action/:id [POST]
- /:controller/:action/:id [PUT]
- /:controller/:action/:id [DELETE]
Here are a few examples:
'/users/list' # => routes to UsersController#list '/users/show/1' # => routes to UsersController#show, params[:id] == 1
Other 'basic' routes can be defined as follows:
Mack::Routes.build do |r| r.connect '/', :controller => :default, :action => :home_page r.connect '/hello/world', :controller => :default, :action => :home_page r.defaults end
Now when a route comes in to either '/' or '/hello/world' it will be directed to the DefaultController and the home_page action.
NOTE: It's important to note that the 'default' routes will always be the last routes matched, regardless of where they are placed in the routes.rb file.