LoginSignup
1
2

More than 3 years have passed since last update.

[Ruby on Rails] resourcesの使い方について

Last updated at Posted at 2020-01-20

resourcesに慣れないので理解することを目的に個人のメモとして残します

環境

OS:Windows10
Rubyバージョン:ruby 2.5.3p105 (2018-10-18 revision 65156) [x64-mingw32]
Railsバージョン:Rails 5.2.4.1

resourcesの使い方

routes.rb
Rails.application.routes.draw do

resources :tests

end

上記のようにroutes.rbでモデルを選んで宣言

resourcesの機能

  • 複数のCRUD処理に関わるルーティングを設定する(下記の表参照)
  • いくつかのURLと同値である簡潔な文字列が使用できる
URLと同値な文字列 httpメソッド URL コントローラー アクション
tests GET /tests tests index
tests POST /tests tests create
new_test GET /tests/new tests new
edit_test GET /tests/:id/edit tests edit
test GET /tests/:id tests show
test PATCH /tests/:id tests update
test PUT /tests/:id tests update
test DELETE /tests/:id tests destroy

同じ文字列でもメソッドが異なるため判別されると考えられる

RESTfulについて

勉強中。随時加筆

1
2
1

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
1
2