ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Rails 4.0新特性介绍

Rails 4.0新特性介绍

原创 Linux操作系统 作者:jieforest 时间:2012-06-28 13:44:43 0 删除 编辑
My previous deep dive into the Rails 4.0 Queueing system was motivated by a patch to Rails I was working on while at RailsCamp New England this past weekend. I'm happy to say that Rails 4.0 now has an optional asynchronous ActionMailer.

The API for pushing your emails to the background is very simple. If you want to make this change application wide simply set it in your application.rb (or in any of the environment files)

CODE:

config.action_mailer.async = trueOr if you want to only make specific mailers asynchrounous

CODE:

class WelcomeMailer < ActionMailer::Base
  self.async = true
endThat's it! Any messages that are being delivered will be sent as a background job. In fact, the rendering is happening on the background as well.
You will need to take care that the arguments you are passing your mailers can be properly marshalled. Instead of:

CODE:

WelcomeMailer.welcome(@user).deliverYou should do:

CODE:

WelcomeMailer.welcome(@user.id).deliverThen in your mailer:

CODE:

class WelcomeMailer < ActionMailer::Base
  def welcome(id)
    @user = User.find(id)
    ...
  end
end

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/301743/viewspace-734050/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-04-23

  • 博文量
    443
  • 访问量
    508546