Custom Routes in Ruby

From the Ruby on Rails cheat sheet · Routes · verified Jul 2026

Custom Routes

Define custom routes and root

ruby
# Root route
root 'posts#index'

# Simple route
get 'about', to: 'pages#about'

# Route with dynamic segments
get 'posts/:id', to: 'posts#show'

# Named routes
get 'dashboard', to: 'dashboard#index', as: :user_dashboard
✅ root route defines homepage (must be first)
💡 Use as: option to create custom path helper
🔍 Constraints validate route parameters
⚡ rails routes | grep posts to filter routes
routescustomhttp

Continue with Ruby on Rails

Save the full cheat sheet or work through every related task.

More Ruby tasks

Back to the full Ruby on Rails cheat sheet