2
3

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.

CRUDと7つのアクション

Posted at

#CRUD
アプリケーションのデータ取り扱いに関して、基本的な処理の頭文字を並べたものです。
アプリケーションの機能は、この4つの処理を組み合わせながら実装します。

C(Create) R(Read) U(Update) D(Delete)
生成 読み取り 更新 削除

Railsでは、CRUDを7つのアクションに分割して、処理を実現します。

7つのアクション

CRUDを実現するためは、それぞれの処理を記述する必要があります。
Ruby on Railsには、それらのアクションの設定が慣習的に決められており、下記の表のようなアクションが存在します。

アクション名 内容
index 一覧表示
new 生成
create 保存
show 詳細表示
edit 編集
update 更新
destroy 削除
これを本カリキュラムでは、「7つのアクション」と呼んでいます。
これらの7つのアクションのルーティングは、resourcesメソッドを使用することで一度に設定が可能です。

#resourcesメソッド
resourcesは、7つのアクションへのルーティングを自動生成するメソッドです。
resourcesの引数に、:articles というシンボルを指定すると/articlesのパスに対応するルーティングが生成されます。

【例】resourcesメソッドの使用例

routes.rb
Rails.application.routes.draw do
  resources :articles
end
2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?