[英]Rails - devise with devise_token_auth not sending confirmation email
I work on project (ruby '2.2.0', rails '4.2.3') which use both standard devise user management (for web page) and devise_token_auth (for API part of the service). 我正在研究项目(红宝石“ 2.2.0”,导轨“ 4.2.3”),该项目同时使用标准的devise用户管理(针对网页)和devise_token_auth(针对服务的API部分)。 Everything works fine unless I 除非我一切正常
include DeviseTokenAuth::Concerns::User
in the models/user.rb. 在models / user.rb中。 Then sending confirmation emails after user registration does not occur. 然后在没有用户注册后发送确认电子邮件。
I would be grateful for the solution of this problem. 对于该问题的解决,我将不胜感激。
My models/user.rb: 我的模型/user.rb:
class User < ActiveRecord::Base
# Include devise modules.
devise :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, :omniauthable
include DeviseTokenAuth::Concerns::User
enum role: [:user, :vip, :admin]
after_initialize :set_default_role, :if => :new_record?
def set_default_role
self.role ||= :user
end
end
routes.rb: routes.rb中:
Rails.application.routes.draw do
# standard devise routes available at /users
# NOTE: make sure this comes first!!!
devise_for :users
# token auth routes available at /api/v1/auth
namespace :api do
scope :v1 do
mount_devise_token_auth_for 'User', at: 'auth'
end
end
end
I got the same problem to you. 我也遇到了同样的问题。 This workaround helped me 这个解决方法对我有帮助
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable
include DeviseTokenAuth::Concerns::User
after_create :send_confirmation_email, if: -> { !Rails.env.test? && User.devise_modules.include?(:confirmable) }
private
def send_confirmation_email
self.send_confirmation_instructions
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.