我已经设计了我的rails应用程序 . 我添加了确认,并发送电子邮件确认电子邮件帐户,并在发展环境中正确发送 .
我还添加了可恢复的选项:
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
但是当我转到“忘记密码”并输入电子邮件时,它不会发送任何内容 . 我真的在努力弄清楚为什么可恢复的电子邮件不起作用 . 我很确定这不是我的电子邮件设置,因为它适用于确认 . 有人可以提供有关调试的任何想法吗?或从哪里开始研究为什么可恢复不起作用?
非常感谢提前 .
我忘记密码时按下提交按钮时的日志:
Started POST "/users/password" for 127.0.0.1 at 2014-11-28 01:54:07 -0500
ActiveRecord::SchemaMigration Load (1.0ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by PasswordsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"bGrcwyIqwkeC51TOLyoDqX1bTj2XKNH9RHU7qJ01Zfs=", "user"=>{"email"=>""}, "commit"=>"Reset Password"}
Rendered devise/passwords/new.html.erb within layouts/application (8.8ms)
Rendered layouts/_header.html.erb (4.2ms)
这是我注册新用户时的日志(可确认):
Rendered devise/mailer/confirmation_instructions.html.erb (1.4ms)
Devise::Mailer#confirmation_instructions: processed outbound mail in 33.6ms
Sent mail to test19@test.com (223.6ms)
Date: Fri, 28 Nov 2014 02:29:45 -0500
From: test
Reply-To: test
To: test19@test.com
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
为什么不可恢复激活devise :: mailer?
我的User.rb:
class User < ActiveRecord::Base
extend FriendlyId
friendly_id :username, use: [:slugged, :finders]
def should_generate_new_friendly_id?
username_changed?
end
#validates :username, :uniqueness => {:case_sensitive => false},
#:format => { with: /\A[a-zA-Z0-9]+\Z/ }
validates :firstname, presence: true
validates :lastname, presence: true
validates :country, presence: true
validates :birthday, presence: true
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
attr_accessor :login
validates_with AttachmentSizeValidator, :attributes => :avatar, :less_than => 1.megabytes
acts_as_voter
acts_as_messageable
acts_as_votable
is_impressionable
has_attached_file :avatar, :styles => {
:medium => "300x300>",
:thumb => "100x100#",
:small => "50x50#",
:tiny => "35x35>",
:header => "30x30#" },
default_url: ActionController::Base.helpers.image_path('silhouette.png')
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
def self.find_first_by_auth_conditions(warden_conditions)
conditions = warden_conditions.dup
if login = conditions.delete(:login)
where(conditions).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first
else
where(conditions).first
end
end
end
2 回答
您是否在users表中添加了可恢复模块所需的正确字段?如果没有,则运行此迁移
运行此命令后,重新启动服务器并再试一次
或者,在
devise/password/new.html.erb
中的form_for
标记内添加这些行,您将在视图中获得确切的错误因此,当您的
username
字段产生问题时,您可以添加before_update
回调,试试这个为了确保,您能否确认以下步骤:
在config / environments / developement.rb中确认您已拥有此项
在运行迁移时,您能否仔细检查是否取消注释了所有这些行:
我还会在config / environments / developement.rb中推荐这个