LoginSignup
0
0

More than 1 year has passed since last update.

rails g devise:installでNameError

Last updated at Posted at 2023-03-03

概要

Railsで認証機能を実装する為、Gemのインストールを開始していたところrails g devise:installでNameErrorが発生しました。
その解決法を紹介したいと思います。

エラー内容

エラー内容は以下になります。

NameError: uninitialized constant User

エラーが出たコマンドは以下です
bundle exec rails g devise:install

エラーで調べてみると以下のQ&Aを見つけ、参考に致しました。
`const_get': uninitialized constant User (NameError)

理由/解決法

エラーの理由としては、config/routes.rb内を見てみるとmount_devise_token_auth_for 'User', at: 'auth'とあり、すでにUserモデルが作られているからです。
実際のコードは以下になります。

config/routes.rb
Rails.application.routes.draw do
  mount_devise_token_auth_for 'User', at: 'auth'
end

その為、私の場合はmount_devise_token_auth_for 'User', at: 'auth'をコメント化するか、消すと解決致しました。

その他、参考になりそうな記事

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