【问题标题】:Migrating to OmniAuth 1.0: undefined method `user_omniauth_authorize_path'迁移到 OmniAuth 1.0:未定义的方法 `user_omniauth_authorize_path'
【发布时间】:2012-02-22 09:06:41
【问题描述】:

尝试将我的应用从 Rails 3.0 迁移到 3.2,作为其中的一部分,我还更新了 Devise gem。原来,新的设计需要新的 OmniAuth gem。我使用 OmniAuth 配置了 Facebook 授权。阅读迁移指南后,我还添加了 omniauth-facebook gem 并在 devise.rb 中进行了配置。

现在我收到此错误:

ActionView::Template::Error(未定义的方法 `user_omniauth_authorize_path' 用于 #)

我正在使用此路径作为 Facebook 登录按钮。我现在应该使用什么?

用户模型包含这个(user.rb):

 # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable, :lockable and :timeoutable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :omniauthable

完整的服务器日志:

Started GET "/" for 127.0.0.1 at 2012-02-22 10:39:27 +0200
Processing by PagesController#guardian as HTML
[paperclip] Duplicate URL for photo with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in Asset class
  Rendered pages/guardian.html.erb within layouts/application (955.6ms)
Completed 500 Internal Server Error in 1245ms

ActionView::Template::Error (undefined method `user_omniauth_authorize_path' for #<#<Class:0x00000003b213f0>:0x00000003b01e88>):
    30:     </p>
    31:             </td>
    32:             <td>
    33:             <%= link_to "Login with Facebook", user_omniauth_authorize_path(:facebook), :class => "login_with_facebook_button" %>
    34:             </td>
    35:         </tr>
    36:     </table>
      app/views/pages/guardian.html.erb:33:in `_app_views_pages_guardian_html_erb___1979224720320394612_27892940'

更新:好的,我设法解决了这个路径问题。现在点击 Facebook 登录按钮时,我得到了这个:

Started GET "/users/auth/facebook" for 127.0.0.1 at 2012-02-23 16:02:01 +0200

NoMethodError (undefined method `include?' for nil:NilClass):
  omniauth (1.0.2) lib/omniauth/strategy.rb:165:in `call!'
  omniauth (1.0.2) lib/omniauth/strategy.rb:148:in `call'
  warden (1.1.1) lib/warden/manager.rb:35:in `block in call'
  warden (1.1.1) lib/warden/manager.rb:34:in `catch'
  warden (1.1.1) lib/warden/manager.rb:34:in `call'

这一切有点令人困惑。在我根据本教程指定 :facebook 参数后,路径问题得到解决:https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview。现在我还注意到我在 config/initializers 文件夹中丢失了 omniauth.rb,该文件夹在 omniauth-facebook wiki 中提到。我创建了带有以下内容的omniauth.rb,但仍然遇到同样的问题:

Rails.application.config.middleware.use OmniAuth::Builder do
    provider :facebook, ENV['APP_ID'], ENV['APP_SECRET']
  end

【问题讨论】:

  • 你能粘贴完整的堆栈跟踪吗?
  • 您是否在您的用户模型中添加了omniauthable?
  • 是的。在问题中添加了代码 sn-p。
  • 你已经在你的 devise.rb 初始化器中配置了你的 facebook 吗?

标签: ruby-on-rails facebook devise omniauth


【解决方案1】:

我通过再次运行设计生成器解决了这个问题。需要验证的两个文件是:config/routes.rb 和 models/user.rb

在 routes.rb 文件中,顶部将有一个重复的“devise_for”,并且 user.rb 将具有默认设计模块,因此需要在此处添加“omniauthable”。

【讨论】:

  • 您是指这些生成器吗? &gt;rails generate model service user_id:integer provider:string uid:string uname:string uemail:string &gt;rails generate controller services
  • 我仍然遇到同样的问题。运行 rake routes 也不会列出此路径。我想知道这条路径最初是在哪里指定的。
  • 好的,通过在 devise.rb 中正确指定 facebook 参数来解决这个问题。现在点击登录按钮时出现新问题:NoMethodError (undefined method include?'对于 nil:NilClass):omniauth (1.0.2) lib/omniauth/strategy.rb:165:in call!'
  • 我的意思是设计生成器。 “bundle exec rails generate devise:install”和“bundle exec rails generate devise User”(用于用户模型)。另外,请参阅 github.com/plataformatec/devise/wiki/OmniAuth:-Overview。这有一个 FB 示例演练,以防万一您不会错过任何配置值。
  • 好的,我想我会为这个 NoMethodError 创建一个单独的问题。原来的问题在这里解决了,谢谢!
【解决方案2】:

在用户模型上放置设计:omniauthable。目前我的版本是 设计 2.0.4、omniauth 1.1.0 和omniauth-facebook 1.2.0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-17
    • 2011-06-05
    • 1970-01-01
    相关资源
    最近更新 更多