Rails 4.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)
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:
def welcome(id)
@user = User.find(id)
...
end
end
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 asynchrounousCODE:
class WelcomeMailer < ActionMailer::Baseself.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::Basedef welcome(id)
@user = User.find(id)
...
end
end
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-734050/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Apache Cassandra 4.0新特性介紹Apache
- Redis4.0的新特性介紹Redis
- iOS 8 新特性介紹iOS
- Node.js 4.0 中的 ES 6 特性介紹Node.js
- Angular 8的新特性介紹Angular
- JavaScript 6 的新特性介紹JavaScript
- TiDB 5.0.0新特性介紹TiDB
- [譯] Chrome 71 新特性介紹Chrome
- webpack4新特性介紹Web
- MySQL 8.0新特性更新介紹MySql
- Chrome 63 Beta新特性介紹Chrome
- JDK1.5新特性介紹JDK
- AnalyticDB for PostgreSQL 6.0 新特性介紹SQL
- Chrome 66 開發者工具新特性介紹Chrome
- Dash 2.16版本新特性介紹
- Rails 5 有什麼新特性?AI
- React v16.6 新特性介紹React
- SQL?Server新特性SequenceNumber用法介紹YTZBSQLServer
- Flutter 3.7 新特性:介紹後臺isolate通道Flutter
- 簡短介紹 C# 6 的新特性C#
- rails4.0 session activerecordAISession
- MyRocksTTL特性介紹
- Android新特性介紹,ConstraintLayout完全解析AndroidAI
- MySQL5.6版本的新特性介紹MySql
- Java EE 7 三大新特性的介紹Java
- TiDB 4.0 新特性嚐鮮指南TiDB
- HashSet的特性介紹
- ECMAScript6.0新特性介紹第七篇
- 【劉文彬】 EOS1.1版本新特性介紹
- 【DATAGUARD】DG系列之11g新特性簡單介紹
- Zookeeper 節點特性介紹
- Mycat關鍵特性介紹
- MySQL 8.0 新增特性介紹MySql
- MySQL·引擎特性·InnoDBChangeBuffer介紹MySql
- cassandra壓縮特性介紹
- 認識 MongoDB 4.0 的新特性——事務(Transactions)MongoDB
- Node.js 4.0的ES6新特性。Node.js
- Java SE 6 新特性: Java DB 和 JDBC 4.0JavaJDBC