加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rails设计不发送确认电子邮件但需要

发布时间:2020-12-17 04:32:18 所属栏目:百科 来源:网络整理
导读:我设置了Devise并且能够创建个人资料.当我创建配置文件并尝试登录时,收到一条错误消息,表明我尚未确认我的帐户, 我从未收到过我应该确认自己帐户的电子邮件.我选择这样的选项出错了,还是没让Devise给我发电子邮件? 这是我过去的迁移: class DeviseCreateUs
我设置了Devise并且能够创建个人资料.当我创建配置文件并尝试登录时,收到一条错误消息,表明我尚未确认我的帐户,

我从未收到过我应该确认自己帐户的电子邮件.我选择这样的选项出错了,还是没让Devise给我发电子邮件?

这是我过去的迁移:

class DeviseCreateUsers < ActiveRecord::Migration
  def self.up
    create_table(:users,:options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8') do |t|
      t.database_authenticatable :null => false
      t.recoverable
      t.rememberable
      t.trackable
      t.confirmable
      t.encryptable
      t.column "first_name",:string  
      t.column "last_name",:string
      t.column "organization_name",:string

      t.timestamps
    end

    add_index :users,:email,:unique => true
  end

  def self.down
    drop_table :users
  end
end

解决方法

在开发模式下,您必须将此行添加到config / environments / development.rb

config.action_mailer.default_url_options = {:host => ‘localhost:3000’}

然后,检查服务器日志以查看邮件.你应该找到类似的东西:

Rendered devise/mailer/confirmation_instructions.html.erb (19.5ms)

Sent mail to example@mail.com (21951ms)

Date: Thu,26 May 2011 12:56:55 +0200

From: sender@mail.com

Reply-To: sender@mail.com

To: example@mail.com

Message-ID: <4dde31f7944bd_5ac277e0e4785c6@L-Portable.mail>

Subject: Confirmation instructions

Mime-Version: 1.0

Content-Type: text/html;

charset=UTF-8

Content-Transfer-Encoding: 7bit
<p>Welcome example@mail.com!</p>
<p>You can confirm your account through the link below:</p>
<p><a href="http://localhost:3000/users/confirmation?confirmation_token=Hi0tyRQU8cCFpAbatYFf">Confirm my account</a></p>

您还需要将此行放在config / initializers / devise.rb中

config.mailer_sender = "sender@mail.com"

如果您的日志中确实没有此邮件,您仍然可以通过获取数据库中的confirmation_token值来验证您的帐户,然后转到此链接

http://localhost:3000/users/confirmation?confirmation_token= #PUT_YOUR_TOKEN_HERE

这应该可以解决问题.

干杯

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读