OmniAuth/Rails-当您不期望它时,您有一个nil对象 [英] OmniAuth / Rails - You have a nil object when you didn't expect it

查看:56
本文介绍了OmniAuth/Rails-当您不期望它时,您有一个nil对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Rails应用程序中出现以下错误,我不知道如何调试或修复它:

I'm getting the following error in my Rails application and I have no idea how to go about debugging or fixing it:

NoMethodError在 AuthenticationsController#create

NoMethodError in AuthenticationsController#create

当您没有时,您有一个nil对象 期待它!您可能已经预料到 ActiveRecord :: Base的实例.这 评估为nil时发生错误.[]

You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[]

Rails.root: /Users/phil/Sites/travlrapp.com 应用程序跟踪|框架跟踪| 完整跟踪

Rails.root: /Users/phil/Sites/travlrapp.com Application Trace | Framework Trace | Full Trace

app/controllers/authentications_controller.rb:15:in `创建'

app/controllers/authentications_controller.rb:15:in `create'

控制器是这样的:

class AuthenticationsController < ApplicationController
  def index
    @authentications = current_user.authentications if current_user
  end

    def create

        omniauth = request.env["omniauth.auth"]

        unless omniauth
            redirect_to authentications_url
            flash[:notice] = "Could not authenticate via #{params['provider']}."
        end

        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'], :token => omniauth['credentials']['token'], :secret => omniauth['credentials']['secret'])
            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


  def destroy
    @authentication = current_user.authentications.find(params[:id])
    @authentication.destroy
    flash[:notice] = "Successfully destroyed authentication."
    redirect_to authentications_url
  end
end

OmniAuth以前可以正常工作,然后我将其混搭起来,试图替换为支持flickr的pchilton的叉子.我是通过在gemfile中设置:git =>并尝试重新安装来完成此操作的,但我不确定我是否做对了.

OmniAuth used to work fine, then I mashed it up trying to swap to a fork by pchilton which supported flickr. I did this by setting :git => in the gemfile and trying to reinstall but im not confident I ever did it right.

我现在已经手动删除了所有omniauth和oafoo gem文件,并首先安装了当前的稳定版(0.1.6)和git master副本,但是所有错误都相同.

I have now manually removed all omniauth and oa- foo gem files and installed first the current stable (0.1.6) and the git master copy but all errors are the same.

这里真是一头雾水,我认识的人都不知道是什么问题.

Really at a loss here, nobody I know has any idea what the problem is.

推荐答案

这似乎是在随机修复.走吧!

This seemed to randomly fix itself. Go Rails!

这篇关于OmniAuth/Rails-当您不期望它时,您有一个nil对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆