Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 3设计忘记密码和多封电子邮件_Ruby On Rails_Ruby On Rails 3_Devise - Fatal编程技术网

Ruby on rails Rails 3设计忘记密码和多封电子邮件

Ruby on rails Rails 3设计忘记密码和多封电子邮件,ruby-on-rails,ruby-on-rails-3,devise,Ruby On Rails,Ruby On Rails 3,Devise,我已经用Desive设置了Rails 3,但有一点小小的改变:我将所有用户的电子邮件存储在电子邮件表中,每个用户可以有多封电子邮件。我遇到了忘记密码功能的问题。我知道,我将不得不重写一些方法,设计用于查找用户电子邮件,然后发送密码重置,但我不知道从哪里开始。非常感谢您为我提供的任何建议。请参阅我对类似问题的解答。您可以在designe::mailer中创建一个覆盖邮件头的邮件程序,使其发送到多个电子邮件: def headers_for(action) #grab the emails so

我已经用Desive设置了Rails 3,但有一点小小的改变:我将所有用户的电子邮件存储在
电子邮件
表中,每个用户可以有多封电子邮件。我遇到了忘记密码功能的问题。我知道,我将不得不重写一些方法,设计用于查找用户电子邮件,然后发送密码重置,但我不知道从哪里开始。非常感谢您为我提供的任何建议。

请参阅我对类似问题的解答。您可以在
designe::mailer
中创建一个覆盖邮件头的邮件程序,使其发送到多个电子邮件:

def headers_for(action)
  #grab the emails somehow
  @emails = resource.emails.map{|email| email.column_name}
  if action == :reset_password_instructions
    headers = {
      :subject       => translate(devise_mapping, action),
      :from          => mailer_sender(devise_mapping),
      :to            => @emails,
      :template_path => template_paths
    }
  else
    # otherwise send to the default email--or you can choose just send to all of them regardless of action.
    headers = {
      :subject       => translate(devise_mapping, action),
      :from          => mailer_sender(devise_mapping),
      :to            => resource.default_email,
      :template_path => template_paths
    }
  end

  if resource.respond_to?(:headers_for)
    headers.merge!(resource.headers_for(action))
  end

  unless headers.key?(:reply_to)
    headers[:reply_to] = headers[:from]
  end
  headers
end

designe从模型方法“email”获取电子邮件地址。因此,如果使用电子邮件模型将所有电子邮件存储在电子邮件表中,则可以在用户模型中定义“电子邮件”方法,并从电子邮件表返回地址

class User < ActiveRecord::Base
  devise :database_authenticatable, :recoverable, :rememberable, :authentication_keys => [ :login ], :reset_password_keys => [ :login ]
  has_many :emails
  ...
  def email
    emails.map{|record| record.email }
  end
end
class用户[:登录],:重置\u密码\u密钥=>[:登录]
有很多:电子邮件
...
def电子邮件
emails.map{| record | record.email}
结束
结束