Circular dependency detected while autoloading constant User

别说谁变了你拦得住时间么 提交于 2019-11-28 00:49:06

Where was your registrations_controller.rb saved to? The location is important. I found that I was making a mistake saving it to app/controllers/devise/.. It simply needed to be saved in app/controllers/. e.g.:

app/controllers/registrations_controller.rb


Also, config/routes.rb route should be defined as:

devise_for :users, controllers: { registrations: 'registrations' }

I got same problem with some classes in lib (used config.autoload_paths += Dir["#{config.root}/lib/**/"])

for me helped to switch rails from 4.0.0.rc1 to 4.0.0

Well, I got relief after adding the following line in my development.rb

config.middleware.delete Rack::Lock

Reference: https://github.com/websocket-rails/websocket-rails/issues/101

You can try this once at last.

I had a similar problem.

And then realised I have the same file duplicated in different folders inside controller, and that was causing the problem.

I had both files with the same content:

  app/controllers/logs_controller.rb
  app/controllers/api/logs_controller.rb

a lot of gems started breaking on rails 4 , all due to the problem of unloadable in controllers. https://github.com/flyerhzm/switch_user/issues/34 https://github.com/thoughtbot/high_voltage/issues/68 https://github.com/thoughtbot/clearance/issues/276 and many more

you should look into errors that which gem is creating the problem. Once you know that: 1) Check the open issues of that gem 2) If that issue exists and fixed , make sure you have that fix or else update the gem. 3)If not you can create an issue and ask them to fix it. 4) If you dont want to wait for their fix , you can form the gem and push a fix for it https://github.com/cashins/email_preview/commit/b34a077a954b98bd086153fae8979ad142667555 all fix are the same(removing unloadable from the specified controller )

Hope it helps.

if nothing helps downgrade your rails version.

I found this works in development.rb:

config.reload_classes_only_on_change = false

(I previously tried deleting Gemfile.lock and running bundle update, as well as changing Rails version, as mentioned here and elsewhere. They didn't work for me.)

I created the same error with a typo, I had

module EmployeeReminderssHelper

when the helper file was called

employee_reminders_helper.rb

(Note the extra 's')

The devise wiki had this to say on the topic:

Ref: https://github.com/plataformatec/devise/wiki/How-To:-redirect-to-a-specific-page-on-successful-sign-in#preventing-redirect-loops

Preventing redirect loops

Because the code for after_sign_in_path_for above only checks if request.referer == sign_in_url, these methods (which call after_sign_in_path_for) will also have to be overridden (else you will encounter redirect loops):

Devise::PasswordsController#after_resetting_password_path_for
Devise::RegistrationsController#after_sign_up_path_for
Devise::RegistrationsController#after_update_path_for

This can be done like so:

# routes.rb
devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords' }

# users/registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
  protected
    def after_sign_up_path_for(resource)
      signed_in_root_path(resource)
    end

    def after_update_path_for(resource)
      signed_in_root_path(resource)
    end
end

# users/passwords_controller.rb
class Users::PasswordsController < Devise::PasswordsController
  protected
    def after_resetting_password_path_for(resource)
      signed_in_root_path(resource)
    end
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!