当 RoR Mailer 系统发送电子邮件时尝试替换 HTML 代码
我正在将 RJS 与 Prototype 结合使用,并尝试在 RoR Mailer 系统发送电子邮件时替换 HTML 代码。简而言之,我的目标是在浏览器加载时在按钮附近显示 .gif 图像。
在我的 app/views/users/reset.js.rjs 文件中,我有以下代码:
page.replace(:action_button, system_image_loading_tag)
page.redirect_to( :root )
在我的 app/controllers/*users_controller.rb* 中,我有以下代码:
def reset
respond_to do |format|
UsersMailer.confirm_reset(user).deliver
format.js
end
end
提交相关表单 I必须等待电子邮件已发送然后浏览器将重定向到根路径。那么,如果我想避免这次失败,我该怎么办呢?最好的方法是什么?
I am using RJS with Prototype and I am trying to replace HTML code while the RoR Mailer system sends an e-mail. In few words I aim to show a .gif image near a button while the browser load.
In my app/views/users/reset.js.rjs file I have this code:
page.replace(:action_button, system_image_loading_tag)
page.redirect_to( :root )
In my app/controllers/*users_controller.rb* I have this code:
def reset
respond_to do |format|
UsersMailer.confirm_reset(user).deliver
format.js
end
end
Submitting the related form I must wait that the e-mail has been sent and then the browser will redirect to the root path. So, if I want avoid to loose this time, what I can do? What is the best way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您遇到的问题与此用户类似。如果您不想在控制器呈现操作之前等待邮件发送,请尝试将电子邮件发送移至后台。如果您已经有了一个运行后台作业的系统,那就太好了!如果没有,这些说明将 DelayedJob 与 ActionMailer 一起使用似乎非常简单,即使我个人没有使用过 DelayedJob。
Sounds like you're having a problem similar to this user. If you don't want to have to wait for the mail to be delivered before your Controller renders the action, try moving the email delivery to the background. If you've already got a system for running background jobs, great! If not, these instructions for using DelayedJob with ActionMailer seem pretty straight-forward, even though I haven't personally used DelayedJob.