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.

初学者による復習[エラーを解決しよう]

Posted at

さて今回も復習も兼ねてアウトプットをしていこうと思う。

今回復習をしていて遭遇したエラーがこちら。

Invalid route name, already in use: 'root'

簡単に説明するとrootが2つ使われていて遷移する際、どっちに遷移して良いか
分からないよ!とエラーが出ているようだ。

修正する前の記述がこちら。

Rails.application.routes.draw do
  devise_for :users
  root to: "rooms#index"
  get 'messages/index'
  root to: "messages#index"
  resources :users, only: [:edit, :update]
  resources :rooms, only: [:new, :create]
end

確かにroot toで指定しているパスが2つありそりゃどっちやねんってエラーで怒られるわけだ。

なので遷移させたい方だけ残して

Rails.application.routes.draw do
  devise_for :users
  root to: "rooms#index"
  get 'messages/index'
  resources :users, only: [:edit, :update]
  resources :rooms, only: [:new, :create]
end

これでエラーが無事解決し指定したページに遷移できるようになった!

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?