[RAILS] Nesting routing ...

Introduction

To nest routes, enclose them in do ~ end.

Nest routes and create URLs

config/routes.rb


resources :class_rooms, only: [:index, :new, :create, :show] do
  resources :messages, only: [:index, :create, :destroy]
  resources :posts, only: [:index, :new, :create]
  resources :users, only: [:show, :edit, :update]
end

By nesting with do ~ end, class_rooms could be put before the URL of messages, posts, users, and ID could be included. I created it with the image of creating a hierarchy.

Recommended Posts

Nesting routing ...
routing
What's happening with routing nesting
About Rails routing
Rails Routing Basics
Rails 6.0 Routing Summary
[Ruby] Nesting each