Why does PDFKit/wkhtmltopdf hang but renders PDF as expected when Rails app is killed?

The problem is with wkhtmltopdf itself, specifically, any version after 0.9.9. wkhtmltopdf hangs when run directly from the command-line. Steps to correct: brew uninstall wkhtmltopdf cd /usr/local/Library/Formula/ git checkout 6e2d550 /usr/local/Library/Formula/wkhtmltopdf.rb brew install wkhtmltopdf Then verify the correct version is installed wkhtmltopdf –version which should yield wkhtmltopdf 0.9.9 Citations: https://github.com/mileszs/wicked_pdf/issues/110 http://wearepandr.com/blog/article/homebrew-and-installing-old-package-versions#blog_nav

How do I create a Mailer Observer

I’m surprised how little there is in Rails’ documentation about this. Basically, ActionMailer in Rails 3 introduces the use of Interceptors (called before the message is sent) and Observers (after the message is sent). To set up an Observer, add the following to an initializer: class MailObserver def self.delivered_email(message) # Do whatever you want with … Read more

Rails: Avoiding duplication errors in Factory Girl…am I doing it wrong?

Simple answer: use factory.sequence If you have a field that needs to be unique you can add a sequence in factory_girl to ensure that it is never the same: Factory.define :user do |user| sequence(:email){|n| “user#{n}@factory.com” } user.password{ “secret” } end This will increment n each time in order to produce a unique email address such … Read more

Setting up a polymorphic has_many :through relationship

To create a polymorphic has_many :through, you must first create your models. We will use’Article,’ ‘Category,’ and ‘Tag’ where ‘Tag’ is the join-model and Article is one of many objects which can be “tagged” with a category. First you create your ‘Article’ and ‘Category’ models. These are basic models which do not need any special … Read more