Ale*_*vin 7 facebook ruby-on-rails devise omniauth
试图将我的应用程序从Rails 3.0迁移到3.2,作为其中的一部分,我也在更新Devise gem.原来,新的Devise需要新的OmniAuth宝石.我有使用OmniAuth配置的Facebook授权.阅读迁移指南后,我还添加了omniauth-facebook gem并在devise.rb中进行了配置.
现在我收到这个错误:
ActionView :: Template :: Error(##:0x00000003b01e88>的未定义方法`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
Run Code Online (Sandbox Code Playgroud)
完整服务器日志:
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'
Run Code Online (Sandbox Code Playgroud)
更新:好的,我设法解决了这个路径问题.现在点击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'
Run Code Online (Sandbox Code Playgroud)
这一切都有点令人困惑.在我指定了本教程中的: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
Run Code Online (Sandbox Code Playgroud)
小智 5
我通过再次运行设计生成器解决了这个问题.需要验证的两个文件是:config/routes.rb和models/user.rb
在routes.rb文件中,顶部会有一个重复的'devise_for',而user.rb将有默认的设计模块,因此需要在这里添加'omniauthable'.
| 归档时间: |
|
| 查看次数: |
3389 次 |
| 最近记录: |