Intern Track Roadmap

Rails routes: basics

This course covers how a Rails app decides which URLs it answers. It starts with config/routes.rb and the draw block that holds every route. It then shows routes written by hand with an HTTP verb, a URL pattern and a controller action, including dynamic segments. Later lessons cover resources and its only: and param: options, named routes with _path and _url helpers, the single root route, and reading the full route list with bin/rails routes. A final lesson traces one route through every idea.

What you'll learn

  • ✓How config/routes.rb and its draw block map requests to controller actions
  • ✓Writing routes with get, post, patch and delete, plus dynamic segments
  • ✓Generating RESTful routes with resources, narrowed by only: and param:
  • ✓Named routes and the difference between _path and _url helpers
  • ✓Declaring the root route and why only one is allowed
  • ✓Listing and filtering routes with bin/rails routes and grep
Free preview · Lesson 1 2 min read

config/routes.rb: the entry point map

In Rails console (IRB), app.get "/articles/1" only worked because a matching entry already existed somewhere. That somewhere is config/routes.rb, the file that decides which URLs an app answers and which controller action handles each.

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...