LoginSignup
1
0

More than 3 years have passed since last update.

【Rails】rails g devise:installで遭遇したUser does not respond to 'devise' method.について

Last updated at Posted at 2021-02-05

状況にぴったりの日本語記事がなさそうなので書いておきます。次のエラーにお困りのかたへ。

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.rbdevise_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

1
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
1
0