2014-01-19 116 views
0

我试图发送密码重新链接到用户的电子邮件,当他点击忘记密码,并输入他的电子邮件ID。链接到密码重置没有得到发送的邮件通过rails动态邮件发送

这是操作邮件的方法,我使用

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. 

回答

1

你应该用你的邮件视图中的网址助手:

A request to reset your password ... 

<%= edit_password_reset_url(@user.perishable_token) %> 

If the above url doesn't work ... 

您只需在您的通知程序方法中为设置实例变量:

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线。

+0

我修改了我的代码并删除了body,并将edit_password_reset_url作为实例变量,它似乎现在正在工作。感谢您的回答。 –