ruby-on-railsroutesnamed-routing

match method in routes.rb


I'm trying to follow this tutorial here but the tutorial seems to use this "match" function.

match '/about',   :to => 'pages#about'

Whenever, I do the same, I get this error from the server:

undefined method `match' for main:Object

How can I edit the routes.rb file such that:

  1. it will route from a long file path to a short one (eg. /pages/about to /about)
  2. I can have a "about_path" variable that I can link to ( eg: <%= link_to "About", about_path %> )

Solution

  • Are you using Ruby on Rails 3? The match router syntax is for Rails 3 only. For previous versions you can define a named route:

    map.about '/about', :controller => 'pages', :action => 'about'