Rails 5:使用omniauth接受服务条款

时间:2019-02-25 11:49:18

标签: ruby-on-rails

我目前正在尝试整合对omniauth facebook的条款的接受程度。

我有一个:terms_of_service字段,但是当我单击facebook按钮时,此字段不会触发。

我尝试了validates_acceptance_of :terms_of_service,但这没用。

在我的“标准”注册中,我使用了<%= f.check_box :terms_of_service, required: true %>

我可以通过Facebook实现类似的功能吗?

我以为使用before_action :terms_of_service, only: [:facebook],但不知道如何检查复选框是否有效

我的用户模型

class User < ApplicationRecord

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

  validates :fullname, presence: true, length: { minimum: 4 }
  validates_acceptance_of :terms_of_service

  has_many :services
  has_many :reservations
  has_many :articles
  has_many :lists
  has_one  :first_reservation, -> { order('created_at ASC')}, class_name: "Reservation"

  def self.from_omniauth(auth)
    user = User.where(email: auth.info.email).first

    if user
      return user
    else
    where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
      user.email = auth.info.email
      user.password = Devise.friendly_token[0,20]
      user.fullname = auth.info.name
      user.image = auth.info.image
      user.uid = auth.uid
      user.provider = auth.provider
      user.skip_confirmation!
    end
  end
end
end

0 个答案:

没有答案