尝试将我的应用从 Rails 3.0迁移到3.2 ,作为其中的一部分,我也在更新Devise gem。事实证明,新的Devise需要新的 OmniAuth 宝石。我有使用 OmniAuth 配置的Facebook授权。阅读迁移指南后,我还添加了omniauth-facebook gem并在devise.rb中配置它。
现在我收到了这个错误:
ActionView :: Template :: Error(未定义的方法 `user_omniauth_authorize_path'for #<#:0x00000003b01e88&GT)
我正在使用此路径登录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 params之后解决了路径问题: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
答案 0 :(得分:5)
我通过再次运行设计生成器解决了这个问题。需要验证的两个文件是:config / routes.rb和models / user.rb
在routes.rb文件中,顶部会有一个重复的'devise_for',而user.rb将有默认的设计模块,因此需要在这里添加'omniauthable'。
答案 1 :(得分:4)
放置设备:omniauthable在用户模型上。目前我的版本是 设计2.0.4,omniauth 1.1.0&amp; omniauth-facebook 1.2.0