ruby-on-rails – 未定义的方法skip_confirmation! – 设计,omniauth

尝试使用devise,omniauth(包括facebook-omniauth)在heroku上托管的应用程序上设置facebook身份验证.
调用facebook API有效,但我无法在回调后跳过确认步骤.

我按照omniauth:https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview上的github教程进行了操作

并阅读并试图实现这一点:
Devise skip_confirmation! not working

但是我的heroku日志中不断出现以下错误

NoMethodError (undefined method `skip_confirmation!')

以下是我的devise.rb的外观:

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:

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模型:

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

谢谢你的帮助 !

解决方法

因此,如果我是对的(不是100%安全),您需要声明您的模型具有可确认的模块,添加可确认模块:
devise :database_authenticatable,:registerable,:recoverable,:rememberable,:trackable,:validatable,:omniauthable,:confirmable

并确保您的用户表上有可确认模块的字段,您应该有字段confirmation_token和confirmed_at

如果您没有这些字段,请查看此answer如何添加它们.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...