title: Circular dependency detected while autoloading constant User
body: <p>I've followed this tutorial (<a href="http://railscasts.com/episodes/236-omniauth-part-2" rel="noreferrer">http://railscasts.com/episodes/236-omniauth-part-2</a>) for creating facebook login with OmniAuth and Devise and I get this error:  Circular dependency detected while autoloading constant User in my routes.rb</p>
  
  <pre><code>  devise_for :users , :controllers =&gt; {:registrations =&gt; 'registrations'}
  </code></pre>
  
  <p>registrations_controller.rb</p>
  
  <pre><code>Class RegistrationsController &lt; Devise::RegistrationsController
  
    def create
      super
      session[:omniauth] = nil unless @user.new_record?
    end
  
    private
  
    def build_resource(*args)
      super
      if session["devise.omniauth"]
        @user.apply_omniauth(session["devise.omniauth"])
        session["devise.omniauth"] = nil
     end
    end
  end
  </code></pre>
  
  <p>and here's my create method from AuthenticationsController</p>
  
  <pre><code>def create
      omniauth = request.env["omniauth.auth"]
      authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
      if authentication
        flash[:notice] = "Signed in successfully."
        sign_in_and_redirect(:user, authentication.user)
      elsif current_user
        current_user.authentications.create!(:provider =&gt; omniauth['provider'], :uid =&gt; omniauth['uid'])
        flash[:notice] = "Authentication successful."
        redirect_to authentications_url
      else
        user = User.new
        user.apply_omniauth(omniauth)
        if user.save
          flash[:notice] = "Signed in successfully."
          sign_in_and_redirect(:user, user)
        else
          session[:omniauth] = omniauth.except('extra')
          redirect_to new_user_registration_url
        end
      end
  end
  </code></pre>