我的 Rails 应用程序出现以下错误,我不知道如何调试或修复它:
AuthenticationsController#create 中的 NoMethodError
当你没想到时,你有一个 nil 对象!您可能期望 ActiveRecord::Base 的实例。评估 nil 时发生错误。[]
Rails.root:/Users/phil/Sites/travlrapp.com 应用程序跟踪 | 框架跟踪 | 全跟踪
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 交换到一个 fork。我通过在 gemfile 中设置 :git => 并尝试重新安装来做到这一点,但我不相信我做对了。
我现在手动删除了所有omniauth 和o-foo gem 文件,并首先安装了当前的stable (0.1.6) 和git 主副本,但所有错误都是相同的。
在这里真的很茫然,我认识的人都不知道问题出在哪里。