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 1 year has passed since last update.

rails routesエラー

Last updated at Posted at 2023-02-23

はじめに

devise使っている為、ルーティング編集をしました。
編集した際に、devise_for :usersとdevise_for :adminがダブって
記述してしまっていた為、エラーが出ていました。


route.rbに下記を追加

route.rb
devise_for :users,skip: [:passwords], controllers: {
  registrations: "user/registrations",
  sessions: 'user/sessions'
}


devise_for :admin, skip: [:registrations, :passwords] ,controllers: {
  sessions: "admin/sessions"
}
$ rails routes

上記のコマンドを打つと・・・・

You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here: 

こんなエラーが出てきた!:frowning2:

「same name」同じ名前があるからエラーみたいな感じ…
route.rbを確認してみると・・・

route.rb
devise_for :admins
devise_for :users
  

devise_for :users,skip: [:passwords], controllers: {
  registrations: "user/registrations",
  sessions: 'user/sessions'
}


devise_for :admin, skip: [:registrations, :passwords] ,controllers: {
  sessions: "admin/sessions"
}

上に
devise_for :adminsとdevise_for :users
があり、下にもある!
devise_for :users,skip:・・・・・
devise_for :admin, skip: ・・・・

ダブっているせいでエラーが出ていたようです。。。

route.rb
 #devise_for :admins
 #devise_for :users
         
「#」コメントアウトすると
エラーが消えてrails routesコマンドで
ルート確認することができました
 
devise_for :users,skip: [:passwords], controllers: {
  registrations: "user/registrations",
  sessions: 'user/sessions'
}

devise_for :admin, skip: [:registrations, :passwords] ,controllers: {
  sessions: "admin/sessions"
}

devise_for :admins
devise_for :users
を「#」コメントアウトして~
rails routesコマンドをまた打ってみると~?

エラーが出ずルート確認することができました:relaxed::clap_tone1:

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?