加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 自动加载常数时检测到循环依赖用户

发布时间:2020-12-16 19:40:37 所属栏目:百科 来源:网络整理
导读:我已经遵循这个教程( http://railscasts.com/episodes/236-omniauth-part-2)用OmniAuth和Devise创建facebook登录,并且我得到这个错误:在我的routes.rb中自动加载常量的用户检测到循环依赖 devise_for :users,:controllers = {:registrations = 'registratio
我已经遵循这个教程( http://railscasts.com/episodes/236-omniauth-part-2)用OmniAuth和Devise创建facebook登录,并且我得到这个错误:在我的routes.rb中自动加载常量的用户检测到循环依赖
devise_for :users,:controllers => {:registrations => 'registrations'}

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的创建方法

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 /中.例如.:

应用程序/控制器/ registrations_controller.rb

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

devise_for:用户,控制器:{注册:’注册’}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读