Thursday 4 June 2009

Send email with PDF attachment in Rails


I am trying to send an email with a PDF attachment via Action Mailer, but somehow when opening email the attachment was corrupted. Been banging my head against the wall for few hours, finally I realised it was because of my Windows development box (I hate you, windows).


So, by default File.read on Linux will open the file in Binary mode in but in Text mode on Windows. To fix this I need to open the file in binary mode before I read it in:

attachment "application/pdf" do |a|
a.filename = File.basename(order_form_content)
File.open(order_form_content, 'rb') do |file|
a.body = file.read
end
end

Security hole with http digest authentication


I came across this blog few days ago, it was a great spot, thought I posted here to help me easy to remember it.


The hole seems to be found in the new version of Rails 2.3, HTTP digest Authentication. You can log in even without an username and password. But HTTP basic authetication doesn't seems to have this problem.

Anyway, read it more here at Nate's Blog