Heroku,Devise:获取“NoMethodError(未定义方法‘to_key’ for :user:Symbol)”

发布于 2024-11-30 22:50:29 字数 1202 浏览 0 评论 0原文

我不知道它何时发生,但我收到此错误 NoMethodError (undefined method 'to_key' for :user:Symbol)

此行为仅发生在 Heroku Cedar 堆栈上。我使用 Devise (1.4.2) 通过 Facebook on 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

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_and_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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挖个坑埋了你 2024-12-07 22:50:29

在本地计算机上执行任何操作之前,请先尝试重新启动 heroku:

$ cd your_app_directory
$ heroku restart

我遇到了完全相同的问题,只需重新启动即可修复它。

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.

千鲤 2024-12-07 22:50:29

我收到同样的错误;但是,它只有在我在omniauth.rb初始化程序中配置主机名后才开始:

OmniAuth.config.full_host = 'http://hostname.com/subdirectory'

我添加了这个,因为我正在运行 Rails3 w/ Passenger在我的根域的子目录中。也许您有相同的覆盖?

我仍然需要纠正 Facebook 无法处理子目录回调的问题(twitter 正确地保留了子目录,而无需覆盖 full_host)。想法?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文