我遵循了本教程( railscasts/episodes/236 -omniauth-part-2 )用于通过OmniAuth和Devise创建Facebook登录,并且我得到这个错误:自动加载常量时检测到循环依赖用户在我的routes.rb中
I've followed this tutorial (railscasts/episodes/236-omniauth-part-2) for creating facebook login with OmniAuth and Devise and I get this error: Circular dependency detected while autoloading constant User in my routes.rb
devise_for :users , :controllers => {:registrations => 'registrations'}registrationrations_controller.rb
registrations_controller.rb
Class RegistrationsController < 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这里是我的来自AuthenticationsController的创建方法
and here's my create method from AuthenticationsController
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 => omniauth['provider'], :uid => 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推荐答案
你的 registrations_controller.rb 保存到?位置很重要。我发现我把一个错误保存到 app / controllers / devise /.中。它只需要保存在 app / controllers /.中,例如:
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.:
controller / registrations_controller.rb
另外, config / routes。 rb 路由应定义为:
devise_for:用户,控制器:{注册:'注册'}
devise_for :users, controllers: { registrations: 'registrations' }
更多推荐
自动加载常数时检测到循环依赖用户
发布评论