自动加载常量用户时检测到循环依赖

编程入门 行业动态 更新时间:2024-10-28 10:34:43
本文介绍了自动加载常量用户时检测到循环依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经按照本教程(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'}

registrations_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.:

app/controllers/registrations_controller.rb

另外,config/routes.rb 路由应该定义为:

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

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

更多推荐

自动加载常量用户时检测到循环依赖

本文发布于:2023-10-30 21:56:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544117.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:常量   检测到   自动加载   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!