Circular dependency detected while autoloading constant User

后端 未结 8 1915
心在旅途
心在旅途 2020-12-06 17:17

I\'ve followed this tutorial (http://railscasts.com/episodes/236-omniauth-part-2) for creating facebook login with OmniAuth and Devise and I get this error: Circular depend

相关标签:
8条回答
  • 2020-12-06 17:47

    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
    
    0 讨论(0)
  • 2020-12-06 17:48

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

    0 讨论(0)
  • 2020-12-06 17:55

    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

    0 讨论(0)
  • 2020-12-06 17:56

    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.

    0 讨论(0)
  • 2020-12-06 17:57

    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' }

    0 讨论(0)
  • 2020-12-06 17:59

    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.

    0 讨论(0)
提交回复
热议问题