0

我按照屏幕铸形瑞安贝茨railscast和除非我改变我的方法,例如如下每一件事情是工作的罚款:Omniauth问题3.1.0

 def create 
     omniauth = request.env["omniauth.auth"] 
     current_user.authentications.create(:provider => omniauth['provider'], :uid =>   omniauth["uid"]) 
     flash[:notice] = "Authentication successful" 
     rescue Exception => e 
     # Just spit out the error message and a backtrace. 
     render :text => "<html><body><pre>" + e.to_s + "</pre><hr /><pre>" + e.backtrace.join("\n") + "</pre></body></html>" 
    end 

def create 
    omniauth = request.env["omniauth.auth"] 
    current_user.authentications.create(omniauth['provider'], omniauth["uid"]) 
    flash[:notice] = "Authentication successful" 
    rescue Exception => e 
    # Just spit out the error message and a backtrace. 
    render :text => "<html><body><pre>" + e.to_s + "</pre><hr /><pre>" + e.backtrace.join("\n") + "</pre></body></html>" 
    end 

我不断收到未定义的方法stringify_keys' for "twitter":String但每件事情都很好地工作的第一种方式。任何想法在这里

回答

1

你变了:

​​

到:

current_user.authentications.create(omniauth['provider'], omniauth["uid"]) 

您将在任何防护栏得到这个错误的应用,因为没有指定哪些字段分配值。 的(从我的应用程序之一)例如:

ruby-1.9.2-p180 :002 > User.create("a", "b") 
NoMethodError: undefined method `stringify_keys' for "a":String 

我认为你的意思如下:

user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth) 
+0

哇,请我怎么能去这个 – Uchenna

+0

这是相同的方式,它是在做railscasts插曲。或者我错过了什么 – Uchenna

+0

我很抱歉,我不知道你在做什么。第一种方法有什么问题? – Gazler