未定义的方法skip_confirmation! - 设计,全方位 [英] undefined method skip_confirmation! - devise, omniauth

查看:276
本文介绍了未定义的方法skip_confirmation! - 设计,全方位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用devise,omniauth(包括Facebook-omniauth)在一个在heroku上托管的应用程序设置Facebook身份验证。
调用facebook API工作,但是我没有设法在回调之后跳过确认步骤。

Trying to set up facebook authentication using devise, omniauth (including facebook-omniauth) on an app hosted on heroku. Call to facebook API works, but I do not manage to skip the confirmation step after callback.

我遵循gmnbub上的github教程: https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

I followed the github tutorial on omniauth : https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

并阅读并尝试实现:
Devise skip_confirmation!不工作

但是,我的英雄日志中出现以下错误:

But I keep getting the following error in my heroku log :

NoMethodError (undefined method `skip_confirmation!')

这是我的设计.rb看起来:

Here is how my devise.rb looks :

config.omniauth :facebook, "API_KEY", "API_SECRET"    

{:strategy_class => OmniAuth::Strategies::Facebook,
:scope => 'email, offline_access', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}

这里是我的omniauth_callbacks_controller.rb:

Here is my omniauth_callbacks_controller.rb :

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
   # You need to implement the method below in your model (e.g. app/models/user.rb)
   @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)

   if @user.persisted?
     sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
    set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
   else
    session["devise.facebook_data"] = request.env["omniauth.auth"]
    redirect_to new_user_registration_url
   end
  end
end 

这是我的user.rb模型:

Here is my user.rb model :

def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
 user = User.where(:provider => auth.provider, :uid => auth.uid).first
 unless user
       user = User.new(name:auth.extra.raw_info.name,
                    provider:auth.provider,
                    uid:auth.uid,
                    email:auth.info.email,
                    password:Devise.friendly_token[0,20],
                    )
       user.skip_confirmation!
       user.save
  end
  user
end



Thanks for your help !

推荐答案

所以如果我是对的(不是100%的安全),你需要声明你的模型具有模块可确认,添加可确认模块:

So if I'm right (not 100% secure), you need to declare that your model has the module confirmable, add the confirmable module:

   devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :confirmable

并确保您具有可确认模块的字段在您的用户表上,您应该有字段confirm_token和confirmation_at

And make sure that you have the fields for the confirmable module on your users table, you should have the fields confirmation_token and confirmed_at

如果没有这些字段,请检查这个 answer 如何添加它们。

If you don't have those fields, check on this answer how to add them.

这篇关于未定义的方法skip_confirmation! - 设计,全方位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆