状況にぴったりの日本語記事がなさそうなので書いておきます。次のエラーにお困りのかたへ。
User does not respond to 'devise' method. This usually means you haven't loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' inside 'config/initializers/devise.rb' or before your application definition in 'config/application.rb' (RuntimeError)
原因: rails g devise:install を後からやろうとしていませんか?
先走って、さきにモデルやら何やら作成して、急に思い出してrails g devise:install
しようとして次のエラーにかかります。私のことです。
$ rails g devise:install
Traceback (most recent call last):
63: from bin/rails:4:in `<main>'
62: from /Users/USER_NAME/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:291:in `require'
61: from /Users/USER_NAME/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:257:in `load_dependency'
60: from /Users/USER_NAME/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.4.4/lib/active_support/dependencies.rb:291:in `block in require'
・
・
・
/Users/USER_NAME/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/devise-4.7.3/lib/devise/rails/routes.rb:510:in `raise_no_devise_method_error!': User does not respond to 'devise' method. This usually means you haven't loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' inside 'config/initializers/devise.rb' or before your application definition in 'config/application.rb' (RuntimeError)
解決法
今回はroutes.rb
の devise_for
〜を削除したところ、rails g devise:install
ができるようになりました(先走りすぎ?)。そのほかdeviseのメソッドを呼び出そうとしている箇所があれば疑ってみると良さそうです。
参考
以下を参考にしました。
getting error from devise “User does not respond to 'devise' method” when running “rails generate devise:install” - stack overflow