设计可以允许多封电子邮件进行密码恢复吗?

时间:2016-05-09 14:34:06

标签: ruby-on-rails ruby devise erb forgot-password

我有以下情况: 包含可用

的人员模型
class Person < ActiveRecord::Base
  include Userable
end

可用包含许多电子邮件:

module Userable extend ActiveSupport::Concern
  included do
    has_one :user, as: :userable
    has_many :emails, as: :emailable, dependent: :destroy
  end
end

电子邮件也有一个模型:

class Email < ActiveRecord::Base
  belongs_to :emailable, polymorphic: true

  validates :address, presence: true,
                      format: { with:
                        /\A[A-Za-z0-9._%+-]+@([A-Za-z0-9.-]+\.)+[A-Za-z]+\z/}
end

最后,用户模型:

class User < ActiveRecord::Base

  # devise properties
  devise :database_authenticatable, :rememberable, :trackable, :timeoutable, :recoverable
end

我试图创建&#34;忘记密码&#34;通过向用户发送电子邮件来恢复用户密码的事情。但问题是&#39;电子邮件&#39;不是用户的方法。所以,当我加载路径&#34; users / password / new&#34;它给了我错误:

  

未定义的方法`电子邮件&#39;对于#User:0x0 ......

那么,有没有办法可以更改我的表单以向个人电子邮件发送电子邮件?

<h2>Forgot your password?</h2>

<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
  <%= devise_error_messages! %>

  <div><%= f.label :email %><br />
  <%= f.email_field :email, :autofocus => true %></div>

  <div><%= f.submit "Send me reset password instructions" %></div>
<% end %>

<%= render "devise/shared/links" %>

0 个答案:

没有答案