我设置了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
这应该可以解决问题.
干杯