LoginSignup
0
0

More than 3 years have passed since last update.

ルーティングのネストを使って、任意のURLにしてみた

Posted at

ルーティングのネストとは

 ルーティングを入れ子にすること。そうすることで、URLに親のコントローラー名を入れることができる。また、アソシエーションしている、別のモデルのid情報を取得することもできる。
個別のページに遷移させたい場合にネストするとよい。

ネストのルーティング方法

ruby:routes.rb
resources :親となるコントローラー do
    resources :子となるコントローラー
end

子となるコントローラーをdo〜endで囲む。
```
ex)


<%= link_to 'チャットルーム', class_room_messages_path(current_user.class_room.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