10
4

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 5 years have passed since last update.

【Rails】Rails g devise 〇〇でin `block in load_missing_constant': uninitialized constant User (NameError)が出てきた時の対処法

Last updated at Posted at 2019-12-12

#現象
Userモデルを作成するため、

rails g devise User

上記コマンドを入力。
ところが

/Users/hogehoge/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/active_support.rb:79:in `block in load_missing_constant': uninitialized constant User (NameError)

というエラーが出てきた。

原因

すでに下記のようにroutes.rbにdevise_for :usersというコードを入れており、ルーティングおかしくなってrailsコマンドがうまくいかなかった。

config/routes.rb
Rails.application.routes.draw do
  devise_for :users
  root 'top#index'
end

#解決策
config/routes.rb内の devise_for :usersを一旦消して、rails g devise Userをするとエラーが出ずに、Userモデルを作成できた。

参照
https://happy-teeth.hatenablog.com/entry/2018/07/21/163123
https://qiita.com/imotan/items/c73fab5ee230114a08b6

10
4
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
10
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?