6.1. Introduction

In Section 3.3, “Creating HTML Dynamically with erb” and Chapter 5, Scaffolding and REST we have already come across routes. The routes contained in config/routes.rb define what happens in the Rails application when a user of a Rails application fetches a URL. A route can be static and dynamic and pass any dynamic values with variables to the controller. If several routes apply to a URL, the one that is listed at the top of config/routes.rb wins.

Buy the new Rails 5.1 version of this book.

If you do not have much time, you can skip this chapter for now and get back to it later if you have any specific questions.
Let's first build a test Rails application so we can experiment:
$ rails new shop
$ cd shop
With rake routes we can display the routes of a project. Let's try it straight away in the freshly created project:
$ rake routes
You don't have any routes defined!

Please add some routes in config/routes.rb.

For more information about routes, see the Rails guide: http://guides.rubyonrails.org/routing.html.
That's what I call a good error message. It's a new Rails project, there are no routes yet.
In case of a new Rails project, the file config/routes.rb has many commented out examples. For the rest of this chapter we pretend that these examples are not there and only display the newly entered routes.

Thank you for your support and the visibility by linking to this website on Twitter and Facebook. That helps a lot!