【问题标题】:Link to password reset not getting sent on the email sent by rails action mailerrails action mailer 发送的电子邮件中未发送密码重置链接
【发布时间】:2014-02-08 14:42:12
【问题描述】:

当用户点击忘记密码并输入他的电子邮件 ID 时,我正在尝试向用户的电子邮件发送密码重新生成链接。

这是我正在使用的动作邮件方法

class Notifier < ActionMailer::Base

default from: "myemailid"
def deliver_password_reset_instructions(user)
email = "myemailid"
subject=       "Password Reset Instructions"     
sent_on  =     Time.now  
body={:edit_password_reset_url=>edit_password_reset_url(user.perishable_token)}
mail(:to=>email,:subject=>subject)


end

end

这是通知器内部的视图

A request to reset your password has been made. If you did not make this request,
simply    ignore this email. If you did make this request just click the link below:

<%= @edit_password_reset_url %>

 If the above URL does not work try copying and pasting it into your browser. 
 If you continue to have problem please feel free to contact us.


 Everything else is getting sent but the link is not sent.

  I cant seem to find out the problem so pls if any one knows how to solve this issue,pls     help.

【问题讨论】:

    标签: ruby-on-rails mailer


    【解决方案1】:

    您应该在电子邮件视图中使用 URL 助手:

    A request to reset  your password ...
    
    <%= edit_password_reset_url(@user.perishable_token) %>
    
    If the above url doesn't work ...
    

    你只需要在你的通知方法中为@user设置实例变量:

    class Notifier < ActionMailer::Base
      def deliver_password_reset_instructions(user)
        @user = user
        mail(:to => @user.email, :subject => 'Password Reset Instructions')
      end
    end
    

    您会注意到也不需要设置 sent_on 时间。视图可以访问操作方法中设置的任何实例变量,因此设置@user 就足够了。不需要你的body 行。

    【讨论】:

    • 我修改了我的代码并删除了正文,并将 edit_password_reset_url 作为实例变量,它现在似乎可以工作了。也感谢您的回答。
    猜你喜欢
    • 2013-05-21
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    • 2011-05-15
    • 2015-09-08
    • 2011-07-14
    • 2016-04-04
    • 2012-07-25
    相关资源
    最近更新 更多