LoginSignup
1
1

More than 3 years have passed since last update.

rails resources

Posted at

resourcesとは

railsで定義されている7つのアクションのルーティングを自動で作成するメソッド
具体的には

アクション名 役割
index リソースの一覧を表示させる
show リソースの詳細を表示させる
new 投稿フォームを表示させる
create リソースを追加させる
edit 更新フォームを表示させる
update リソースを更新させる
destroy リソースを削除する
resources :tweets

get 'tweets'     => 'tweets#index'
    get 'tweets/:id' => 'tweets#show'
    get 'tweets/new' => 'tweets#new'
    post 'tweets' => 'tweets#create'
    get 'tweets/:id/edit' => 'tweets#edit'
    patch 'tweets/:id'  => 'tweets#update'
    delete 'tweets/:id' => 'tweets#destroy'

は同じ意味

複数の場合はコントローラー名を続けて書く

 resources :コントローラー名, :コントローラー名

した二つは同じ意味。onlyはそれのみを許可する。exceptはそれのみを拒否する。

 resources :tweets, only: [:index, :snow]
 resources :tweets, except: [:new, :create, :edit, :update, :destroy]

参考サイト

こちら

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