LoginSignup
0
0

More than 3 years have passed since last update.

routes.rb collectionとmember

Last updated at Posted at 2020-01-22

プログラミング初心者の備忘録です。

routes.rbで自作のルーティングを作りたいとき。

collectionとmemberの違いは、idが付けられるかどうか。
以下に例を記載。

collection

routes.rb
resources :users do
    collection do
      get "logout" 
    end
end
ターミナル.
$ bundle exec rails routes
logout_users GET    /users/logout(.:format)    users#logout

member

routes.rb
resources :users do
    member do
      get 'profile'
    end
end
ターミナル.
$ bundle exec rails routes
profile_user GET   /users/:id/profile(.:format)   users#profile

結果

idを持たせたいかどうかで使い分ける。

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