0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[rails]resourcesでルーティングを設定する方法

Last updated at Posted at 2020-07-31

#resourcesでルーティングを設定する
ルーティングは、個別に設定も可能です。
ただし、railsでの基本的な7つのアクションは開発の際によく使われるので、
そのたびに設定するのは効率的とはいえません。
こんなときは、resourcesメソッドを利用すると、ルーティングを1行書くだけで自動設定されます。

Rails.application.routes.draw do
  resources :blogs
end

rails routesコマンドで確認。

$ rails routes

全てのurlが設定されていることを確認。

$ rails routes
                   Prefix Verb   URI Pattern                                                                              Controller#Action
                    blogs GET    /blogs(.:format)                                                                         blogs#index
                          POST   /blogs(.:format)                                                                         blogs#create
                 new_blog GET    /blogs/new(.:format)                                                                     blogs#new
                edit_blog GET    /blogs/:id/edit(.:format)                                                                blogs#edit
                     blog GET    /blogs/:id(.:format)                                                                     blogs#show
                          PATCH  /blogs/:id(.:format)                                                                     blogs#update
                          PUT    /blogs/:id(.:format)                                                                     blogs#update
                          DELETE /blogs/:id(.:format)                                                                     blogs#destroy
       rails_service_blob GET    /rails/active_storage/blobs/:signed_id/*filename(.:format)                               active_storage/blobs#show
rails_blob_representation GET    /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
       rails_disk_service GET    /rails/active_storage/disk/:encoded_key/*filename(.:format)                              active_storage/disk#show
update_rails_disk_service PUT    /rails/active_storage/disk/:encoded_token(.:format)                                      active_storage/disk#update
     rails_direct_uploads POST   /rails/active_storage/direct_uploads(.:format)                                           active_storage/direct_uploads#create

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?