Heroku, Devise: Getting 'NoMethodError (undefined method `to_key' for :user:Symbol)'
I don't know when it happened but I'm getting this error NoMethodError (undefined method 'to_key' for :user:Symbol)
This behavior only happens on Heroku Cedar stack. I use Devise (1.4.2) for authentication via Facebook on Rails 3.1.0.rc6 and ruby 1.9.2-p290. It happens on the line with sign_in_an开发者_运维问答d_redirect(:user, authentication.user)
. Here's my method:
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
Before doing anything on local computer, try restarting heroku first:
$ cd your_app_directory
$ heroku restart
I had exactly the same problem and a simple restart fixed it.
I'm receiving the same exact error; however, it only started after I configured my hostname in the omniauth.rb initializer as so:
OmniAuth.config.full_host = ‘http://hostname.com/subdirectory’
I've added this because I'm running Rails3 w/ Passenger in a subdirectory off my root domain. Perhaps you have the same override in place?
I still need to remedy Facebook's inability to handle a subdirectory callback (twitter properly preserves the subdirectory without the full_host override). Thoughts?
精彩评论