* You are viewing Posts Tagged ‘Rails’

Rails: Digitally sign outgoing emails (S/MIME)

In this article, I will introduce one method to digitally sign outgoing emails with S/MIME using Ruby on Rails.

require ‘openssl’ vs. Kernel.system openssl

At first, I tried to sign mails using the Ruby OpenSSL library which is basically a lightweight wrapper for libopenssl. However, I was not successful; I found out how to create PKCS7 signatures in general, but not especially for S/MIME mails.

So I decided to use the openssl command line tool that can be invoked like this:
openssl smime -sign -signer $CERT_FILE -passin pass:$CERT_PASS
-in $UNSIGNED_MAIL -out $SIGNED_MAIL -certfile $CERT_CA_FILE
-from ‘your ’ -to ‘recipients <email@address>’
Continue Reading

Rails: Using HTML typography automatically

There’s a way you can use special characters for HTML typography in Rails without much work: Just let your views about raw text and then overwrite the html_escape (h) method:

module ApplicationHelper

def h(s)
super(s). \
gsub(‘(c)’ , ‘&copy’). \
gsub(‘(r)’ , ‘®’). \
gsub(‘(tm)’ , ‘™’). \
gsub(’ 1/2 ‘, ’ ½ ‘). \
gsub(’ 1/4 ‘, ’ ¼ ‘). \
gsub(’ … Continue Reading

Rails 2.3: Using ActiveRecord from within console application

If you use Ruby on Rails and want to have access to ActiveRecord and all the other nifty features from within a standalone Ruby script (for instance, a cronjob script that checks integrity of your data), all you need to do is including the “environment” script that fully sets up the Rails environment. In this case I use the “../config” path because my script is located in the app’s “scripts” directory.

#!/usr/bin/ruby
require ‘../config/environment’

# now all Rails features are available, all plugins loaded etc.

# demo
records = Model.find :all
for r in records
puts ‘Checking ’ + r.name + ’ …’
end

blog.dev001.net is Digg proof thanks to caching by WP Super Cache