我正在尝试通过电子邮件为用户设置注册确认。我正在使用设计进行身份验证。但是我无法从设计控制器访问保存的用户资源,尽管我尝试了一些无用的修补程序。如果有人可以提供帮助,那就太好了!!!
我正在尝试在用户保存后向注册用户发送确认链接。但是我无法将新用户记录作为设计控制器中的任何常用实例变量来获取。
现在我的用户注册控制器看起来像这样:
class Users::RegistrationsController < Devise::RegistrationsController
before_action :select_plan, only: :new
# Extend the default Devise gem behaviour so that
# the users signing up with a Pro account(plan_id 2) should be
# saved with a Stripe subscription function
# Otherwise, save the sign up as usual.
def create
super do |resource|
# @user = User.new(configure_permitted_parameters)
if params[:plan]
resource.plan_id = params[:plan]
if resource.plan_id == 2
resource.save_with_subscription
else
resource.save
end
//These do not works and returns null
//@user = User.find_by_email(params[:email])
//@user = User.find(params[:id]
//@user = resource
UserMailer.registration_confirmation(params[:email]).deliver
flash[:success] = "Please confirm your email address to continue"
redirect_to root_url
end
end
end
private
def select_plan
unless (params[:plan] == '1' || params[:plan] == '2')
flash[:notice] = "Please select a membership plan to sign up."
redirect_to root_url
end
end
end
用户型号:
class User < ApplicationRecord
before_create :confirmation_token
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
belongs_to :plan
has_one :profile
attr_accessor :stripe_card_token
# If Pro user passes the validation for email, password etc. then call Stripe
# and tell Stripe to add a subscription by charging customer's card
# Stripe then returns a customer token in response
# Store the token id as customer id and save the user
def save_with_subscription
if valid?
customer = Stripe::Customer.create(description: email, plan: plan_id, card: stripe_card_token)
self.stripe_customer_token = customer.id
save!
end
end
private
def confirmation_token
if self.confirm_token.blank?
self.confirm_token = SecureRandom.urlsafe_base64.to_s
end
end
def email_activate
self.email_confirmed = true
self.confirm_token = nil
save!(:validate => false)
end
end
任何人都知道从设计控制器发送电子邮件确认电子邮件吗?提前致谢!!!