Routing
Quick Cheatsheet
Mostly taken from devhints.
Resources
resources :books
# BooksController:
# index => GET /books
# new => GET /books/new
# create => POST /books/new
# show => GET /books/:id
# edit => GET /books/:id/edit
# update => PUT /books/:id
# delete => DELETE /books/:id
#
# Helpers:
# new_book_path
# book_path(id)
# edit_book_path(id)Member and Collection
collection is for routes on the collection.
member is for routes on a specific member.
Options
Single Resource
Matching
Redirect
Named Routes
Scopes
Nested Resources (routes)
Assuming an event has many registrations and we want registration routes to be nested under an event, e.g. localhost:3000/events/1/registrations, we can do:
Splitting Up Big Routes Files
(Mostly taken from Matt Boldt's blog post)
GitLab's route files are also a great example.
First you have to make a new draw method into Rails's routing mapper via an initializer
Update your config/routes.rb with the names of files in config/routes/*.rb
New route files
Last updated