2011-08-23 20 views
6

我不知道什麼時候發生的,但我得到這個錯誤NoMethodError (undefined method 'to_key' for :user:Symbol)的Heroku,設計:獲取「(用於NoMethodError未定義的方法`TO_KEY」:用戶:符號)」

此行爲僅發生在Heroku上雪松疊加。我使用Devise(1.4.2)通過Facebook上的Rails 3.1.0.rc6和ruby 1.9.2-p290進行身份驗證。它發生在sign_in_and_redirect(:user, authentication.user)的行上。這是我的方法:

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

    authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid']) 


    if !authentication.nil? 
    flash[:notice] = I18n.t('devise.omniauth_callbacks.success', kind: omniauth['provider']) 

    sign_in_and_redirect(:user, authentication.user) 
    elsif current_user 
    current_user.authentications.create!(provider: omniauth['provider'], uid: omniauth['uid']) 
    redirect_to profile_path, notice: I18n.t('devise.omniauth_callbacks.success', kind: omniauth['provider']) 
    else 
    user = User.new 
    user.apply_omniauth(omniauth) 
    if user.save 
     flash[:notice] = I18n.t('devise.omniauth_callbacks.success', kind: omniauth['provider']) 
     sign_in_and_redirect(:user, user) 
    else 
     session[:omniauth] = omniauth.except('extra') 
     redirect_to new_user_registration_url 
    end 
    end 
end 

回答

9

本地計算機上做任何事情之前,先嚐試重新啓動的Heroku:

$ cd your_app_directory 
$ heroku restart 

我有完全一樣的問題,一個簡單的重新啓動固定它。

+0

我有同樣的問題,但'未定義的方法'encrypted_pa​​ssword =''。重新啓動也爲我工作 - 謝謝 –

+0

謝謝!我有'NoMethodError(未定義的方法'...'同樣的問題,這解決了我的問題。 –

+0

這樣做的竅門。謝謝! – TinkerTank

1

我收到相同的確切錯誤;然而,當我在omniauth.rb初始化配置我的主機名,因此纔開始:

OmniAuth.config.full_host =「http://hostname.com/subdirectory」

我已經添加了這一點,因爲我在離開我的根域的子目錄中運行Rails3 w/Passenger。也許你有相同的覆蓋?

我仍然需要補救Facebook無法處理子目錄回調(twitter正確保留沒有full_host覆蓋的子目錄)。思考?

+0

我的初始化程序中沒有此重寫。我在初始化器中有'提供者:Facebook,'APP_ID','APP_SECRET''。 – Ivan

+1

Twitter是否適合你?從我的結尾看來,這似乎是Facebook的路徑回調問題。 – cgrant

+3

固定。這是我的一個問題。 'authentication.user_id'字段引用了一個不存在的'user'記錄。這些錯誤真的很煩人。再一次,我真的應該寫更多的測試:) – Ivan

相關問題