试图在设计宝石中设置确认

时间:2015-01-30 19:13:19

标签: ruby-on-rails ruby-on-rails-3 email devise

我在Windows机器上使用Rails 3.2和Ruby 4。我试图设置Devise gem的确认方面。宝石工作正常。我从http://railsapps.github.io/rails-environment-variables.html了解到,要实际发送确认电子邮件,我需要设置一个电子邮件帐户。因此,我已经设置了一个临时Gmail帐户;在环境production.rb和test.rb我添加了:

  config.action_mailer.smtp_settings = {
    address: "smtp.gmail.com",
    port: 587,
    domain: "example.com",
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: ENV["xxx@gmail.com"],
    password: ENV["xxx"]
  }

我还没有真正部署应用程序并且正在使用localhost。我已经尝试使用电子邮件地址注册,但没有收到确认邮件。因此,在设置上述设置后,我要求应用重新发送确认说明。但是,确认电子邮件仍然没有到达(也不在垃圾邮件文件夹中)。

服务器说了以下内容:

Started POST "/users/confirmation" for 127.0.0.1 at 2015-01-30 19:57:29 +0100
Processing by Devise::ConfirmationsController#create as HTML
  Parameters: {"utf8"=>"V", "authenticity_token"=>"uqVdcfPNDiDw/BGxHQFCxQf9+IZDJs0fOgpHc1hbMDw=", "user"=>{"email"=>"
xxx@gmail.com"}, "commit"=>"Resend confirmation instructions"}
  User Load (1.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`unconfirmed_email` = 'xxx@gmail.com' LIMIT 1
  User Load (1.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`email` = 'xxx@gmail.com' LIMIT 1
  User Load (1.0ms)  SELECT `users`.* FROM `users` WHERE `users`.`confirmation_token` = 'a6f9b9d801276572386b15945ff8
925c7f975c3958f3e2b3dfdd03ff3ba4de88' LIMIT 1
   (0.0ms)  BEGIN
   (1.0ms)  UPDATE `users` SET `confirmation_token` = 'a6f9b9d801276572386b15945ff8925c7f975c3958f3e2b3dfdd03ff3ba4de
88', `confirmation_sent_at` = '2015-01-30 18:57:30', `updated_at` = '2015-01-30 18:57:30' WHERE `users`.`id` = 1
   (54.7ms)  COMMIT
  Rendered devise/mailer/confirmation_instructions.html.erb (2.0ms)

Sent mail to xxx@gmail.com (521ms)
Date: Fri, 30 Jan 2015 19:57:32 +0100
From: xxx@gmail.com
Reply-To: xxx@gmail.com
To: xxx@gmail.com
Message-ID: <54cbd41c501b_11781f9341c148ad@Desktop.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Welcome xxx@gmail.com!</p>

<p>You can confirm your account email through the link below:</p>

<p><a href="http://localhost:3000/users/confirmation?confirmation_token=m6vs52qoWGFX1pM6bqss">Confirm my account</a><
/p>

Redirected to http://localhost:3000/users/sign_in
Completed 302 Found in 3113ms (ActiveRecord: 0.0ms)

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我已经开始工作了。错误是production.rb和test.rb:

user_name: ENV["xxx@gmail.com"],
password: ENV["xxx"]

这应该是:

user_name: "xxx@gmail.com",
password: "xxx"