我不知道什么时候出现了这个错误
NoMethodError (undefined method 'to_key' for :user:Symbol)
只有在Heroku Cedar堆栈上才会出现此行为。我使用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
undefined method 'encrypted_password='
。重启后问题得到解决 - 谢谢。 - Peter Nixey