2011-12-14 22 views
2

我已經運行bundle exec rake db:migrate並有2個數據庫。我也在開發中使用SQLite。 我收到以下錯誤,當我去http://localhost:3000/auth/facebookOnmiauth-Facebook不保存facebook_id給用戶表

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

它指向這段代碼的應用程序/控制器/ sessions_controller.rb:12:'創建」 :

def create 
     auth_hash = request.env['omniauth.auth'] 

     @authorization = Authorization.find_by_provider_and_uid(auth_hash["provider"], auth_hash["uid"]) 
     if @authorization 
     render :text => "Welcome back #{@authorization.user.name}! You have already signed up." 
     else 
######line 12-> user = User.new :name => auth_hash["user_info"]["name"], :email => auth_hash["user_info"]["email"] 
     user.authorizations.build :provider => auth_hash["provider"], :uid => auth_hash["uid"] 
     user.save 

     render :text => "Hi #{user.name}! You've signed up." 
     end 
    end 

我認爲這意味着我的信息數組是空的,並縮小了我的理由,即數據沒有保存到我的數據庫中。

順便說一句,我在第6步以下http://net.tutsplus.com/tutorials/ruby/how-to-use-omniauth-to-authenticate-your-users/

+0

你有沒有解決這個問題?我有完全相同的問題。 – John 2011-12-28 02:18:15

回答

2

確定。我想我知道這個例子出錯了。在上述網站中使用的示例使用了先前版本的omniauth,它使用「user_info」作爲哈希的名稱。新的1.0版omniauth將該名稱改爲「info」,並將提供者策略分割爲不同的gem,因此您必須在Gemfile中分別指定它們(例如:omniauth-facebook,omniauth-twitter等)。所以你不要在Gemfile中使用純粹的'omniauth'gem了。

https://github.com/intridea/omniauth/wiki/Upgrading-to-1.0