简体   繁体   English

在设计中跳过确认邮件

[英]Skip confirmation mail in devise

I want to skip the sending of confirmation mail from devise in my rails 4 application.我想在我的 rails 4 应用程序中跳过从设计发送确认邮件。 I tried so many things, but none of them worked.我尝试了很多东西,但没有一个奏效。

In my user.rb在我的user.rb

before_create :my_method

def my_method
    self.skip_confirmation
end

I tried this also我也试过这个

before_create :my_method

def my_method
    !confirmed
end

I tried removing :confirmable from user.rb but none of them seems to work.我尝试从user.rb删除 :confirmable 但它们似乎都不起作用。 Thanks in advance :)提前致谢 :)

Note : If you want to skip only on certain places 注意 :如果您只想在某些地方跳过

If you are calling User.create before skip_confirmation! 如果要在skip_confirmation之前调用skip_confirmation! , you need to call User.new and user.save . ,您需要调用User.newuser.save

 @user = User.new(:first_name => "John", :last_name => "Doe")
 @user.skip_confirmation!
 @user.confirm!
 @user.save

A/C to your way 随行空调

before_create :my_method

def my_method
    self.skip_confirmation!
    self.confirm!
end

excluding the term confirmable in devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable should skip in a whole 排除devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable confirmable的术语devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable应该整体跳过

Try adding this to user.rb 尝试将其添加到user.rb

protected

def confirmation_required?
 false
end

Try this 尝试这个

@user = User.new(:email => 'email@example.com', :password => 'password') 
@user.skip_confirmation_notification!
@user.save

skip_confirmation_notification! generate a confirmation token but does not send confirmation email. 生成确认令牌,但不发送确认电子邮件。

For every User instance:对于每个User实例:

class User < ApplicationRecord
  after_initialize do |user|
    user.skip_confirmation_notification!
  end
end

For some particular instance:对于一些特定的例子:

john = User.new
john.skip_confirmation_notification!

PS The answers above are about disabling the confirmation process entirely, whereas the author asked about disabling just sending an email. PS 上面的答案是关于完全禁用确认过程,而作者问的是禁用仅发送电子邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM