A blog post a month!
Dream big\b\b\b moderately
Saturday, January 30, 2010
Wednesday, December 9, 2009
Problem: You want to create a remote branch in git.
Problem: How to set up a Rails server the right way
Sunday, November 8, 2009
Problem: your JavaScript code is from the 90's
Saturday, November 7, 2009
Problem: You want to organize and apply best practices to your javascript code.
Friday, November 6, 2009
Problem: Your static assets are missing after a deploy
Problem: Your static assets are missing after a deploy
Solution: Bundle your assets during deployment
Source: http://overstimulate.com/articles/deploy-rails-missing-stylesheets
Sunday, August 9, 2009
Simplify sending emails in Rails
Problem
Sending emails can be painful in Rails.
Why?
- No REST-like conventions. Should I divide my mailers by model or just put them all in one big Notifier class (as implied in the API)? How should I name my email methods?
- Lack of visibility. When writing views, you can check out the view in your browser as you are writing it. With emails, you can only view the email when its sent to your inbox. If the email depends on an event in your app, you have to redo that event anytime you need to view the email.
How we lessened the pain
Write a generic mailer
With the help of this blog post, we wrote our own generic mailer:
Now, we can send emails like so:
That's one less email method definition to worry about!
Note that template_name is used to determine the subject (take from the localization file) and the name of the template. Templates are saved in generic_mailer/<objects>/<template_name>. In the above example, the user_created_a_feedback.html.erb file should be under generic_mailer/feedbacks.
Test if you're sending the right email to the right people
For t(:key) to get the localization, we added the following test helper:
Preview the email on your browser
Since Rails is the golden hammer to all problems, it is what I used to preview the emails on my browser (instead, of say, using an IDE that can do this sort of thing).
There are two parts. The route:
and the controller:
That's about it! Now I can preview the email above in the following url:
http://localhost:3000/generic_mailer/feedbacks/user_created_a_feedback/1
Since you can view sensitive data from this controller, it's important to secure this controller before you release to production.
Testing your emails manually
We use http://www.mailinator.com to test our emails, i.e. in our staging environment, all our user emails end with "@mailinator.com".
Another service that looks interesting is http://litmusapp.com.
Code
Friday, July 24, 2009
About Me
- George Mendoza
- Baguio, Benguet, Philippines
- Start here: http://www.georgemendoza.name/2009/07/you-can-find-me-at.html