1. Welcome
  2. Getting Started [+/-]
    1. Installing from RubyGems
    2. Installing from GitHub.com
    3. Installing with Sake
  3. The Basics [+/-]
    1. Hello World
      1. Application Generation Options
    2. Paths
    3. Environments
    4. Rake
  4. Configuration [+/-]
    1. Configatron
    2. Initializers
      1. Gems
      2. Mime-Types
  5. Routing [+/-]
    1. Default Routes
    2. Named Routes
    3. RESTful/Resource Routes
    4. Nested Resource Routes
    5. Regex Routes
    6. Wildcard Routes
    7. Blocks in Routes
    8. Redirecting
    9. Error Handling
    10. Deferred? Routes
    11. Misc. Routing
  6. Controllers [+/-]
    1. Actions
    2. Headers/Status
    3. Handling Content Types
    4. Filters
    5. Helpers
    6. Layouts
    7. Tell Messaging
    8. Redirecting
    9. Rendering
      1. Engines
        1. Erubis
        2. XML Builder
        3. Extending
          1. Case Study: PDF Writer
      2. Types
        1. :action
        2. :text
        3. :inline
        4. :xml
        5. :url
        6. :partial
        7. :template
        8. :public
        9. Extending
          1. Case Study: PDF Writer
  7. Views [+/-]
    1. Helpers
    2. Layouts
    3. Assets Host
    4. Assets Management
    5. Form Builders
  8. Sessions [+/-]
    1. Session Store API
  9. Request/Response [+/-]
    1. Cookies
  10. Testing [+/-]
    1. RSpec
    2. Test::Unit::TestCase
  11. Porlets [+/-]
    1. Developing
    2. Testing
    3. Packaging
    4. Using
  12. Plugins [+/-]
    1. Extending
      1. Case Study: PDF Writer
  13. Deploying [+/-]
    1. Thin
    2. Passenger (mod_rails)
    3. Joyent Accelerator
  14. Mack More [+/-]
    1. mack-active_record
    2. mack-asset_packager
    3. mack-caching
    4. mack-data_factory
    5. mack-data_mapper
    6. mack-distributed
    7. mack-encryption
    8. mack-facets
    9. mack-haml
    10. mack-javascript
    11. mack-localization
    12. mack-markaby
    13. mack-notifier
    14. mack-orm
    15. mack-pdf_writer
  15. Rails to Mack Cheat Sheet
  16. Contributing
  17. APIs [+/-]

Misc. Routing

There are a few other misc. features in the routing engine.

Mack::Routes.build do |r|
  r.home_page '/', :controller => :default, :action => :index, :host => 'www.example.com'
  r.admin_home = '/', :controller => :admin, :action => :index, :port => 8080, :host => 'admin.example.com'
  r.users_home_page '/', :controller => :users, :action => :show_by_username, :host => ':username.example.com'
  r.resource :users
  r.login '/login', :controller => :sessions, :action => :new, :scheme => 'https'
end

Let's take these routes line by line and see what features we're looking at.

r.home_page '/', :controller => :default, :action => :index, :host => 'www.example.com'

Here we're saying that any request that comes that matches '/' AND the host matches 'www.example.com' send it to DefaultController#index.

home_page_url # => '<current_scheme or http>://www.example.com<:port unless 80 or 443>/'

Next...

r.admin_home = '/', :controller => :admin, :action => :index, :port => 8080, :host => 'admin.example.com'

Here we're saying that any request that comes that matches '/' AND the host matches 'admin.example.com' AND the port is 8080 send it to AdminController#index.

admin_home_url # => '<current_scheme or http>://admin.example.com:8080/'

Next...

r.users_home_page '/', :controller => :users, :action => :show_by_username, :host => ':username.example.com'

Here we're saying that any request that comes that matches '/' AND the host matches '*.example.com' send it to UsersController#show_by_username. We're also going to set params[:username] = the value of '*', so 'http://markbates.example.com' would set params[:username] = 'markbates'.

users_home_page_url(:username => 'markbates') # => '<current_scheme or http>://markbates.example.com<:port unless 80 or 443>/'

Next...

r.resource :users

The standard resource routing applies here. It should be noted that because no host, port, or scheme is specified that the request will match on ANY host, port, or scheme.

Next...

r.login '/login', :controller => :sessions, :action => :new, :scheme => 'https'

Here we're saying that any request that comes that matches '/login' AND the scheme matches 'https' send it to SessionsController#new.

login_url # => 'https://<current_host><:port unless 80 or 443>/login'
This guide was written for Mack version 0.8.2