0
1

More than 3 years have passed since last update.

Rails の routing で namespace, module, scope, as の違い

Posted at

概要

routing を書くときに紛らわしいメソッドをまとめました。

ルーティングの各名称

resources :users


名前付きルーティング      パス                     ディレクトリ
      ↓                ↓                         ↓

   Prefix Verb   URI Pattern               Controller#Action
    users GET    /users(.:format)          users#index
          POST   /users(.:format)          users#create
 new_user GET    /users/new(.:format)      users#new
edit_user GET    /users/:id/edit(.:format) users#edit
     user GET    /users/:id(.:format)      users#show
          PATCH  /users/:id(.:format)      users#update
          PUT    /users/:id(.:format)      users#update
          DELETE /users/:id(.:format)      users#destroy

それぞれのメソッドの対応表

名前付きルーティング パス ディレクトリ
namespace
module × ×
scope × ×
as × ×

きれいな routes ファイルを目指しましょう!

参考:
https://devblast.com/b/rails-5-routes-scope-vs-namespace

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1