[英]rails, devise recoverable not sending emails
我已經在我的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
您是否在用戶表中添加了可恢復模塊所需的適當字段? 如果沒有,請運行此遷移
class AddRecoverableToUsers < ActiveRecord::Migration
def change
add_column :users, :reset_password_token, :string
add_column :users, :reset_password_sent_at, :datetime
end
end
運行此命令后,重新啟動服務器,然后重試
或者,在form_for
devise/password/new.html.erb
form_for
標記內添加這些行,您將在視圖中得到確切的錯誤
<% if f.object.errors.any? %>
<ul>
<% f.object.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
<% end %>
因此,當您的username
before_update
段造成問題時,您可以添加一個before_update
回調,請嘗試
before_validation :check_for_reset_token, if: Proc.new{ |user| user.reset_password_token_changed? }
def check_for_reset_token
self.username = username
end
只是為了確保您可以確認以下步驟:
確認您在config / environments / development.rb中有此文件
config.action_mailer.default_url_options = { host: 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
在運行遷移時,您能否再次檢查一下是否取消對所有這些行的注釋:
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
t.string :unconfirmed_email # Only if using reconfirmable
我也建議在config / environments / development.rb中使用
config.action_mailer.raise_delivery_errors = true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.