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 routes.rbのmemberとcollectionの違い

Posted at

routes.rbのmemberとcollectionの違い

railsのroutes.rbでルーティングを設定する時にmemberとcollectionの違いに関して記載します。

menberの場合

routes.rb
resources :buy_additional_actions, only: %i[] do
   member do
      get 'index' => 'buy_additional_actions#index'

menberの場合は生成されたurlに:idが自動で追加されます。

buy_additional_action GET /buy_additional_actions/:id/index(.:format) buy_additional_actions#index

collectionの場合

routes.rb
resources :buy_additional_actions, only: %i[] do
   collection do
      get 'index' => 'buy_additional_actions#index'

collectionの場合はurlには:idが付与されません。

buy_additional_actions GET /buy_additional_actions/index(.:format) buy_additional_actions#index
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?