Skip to content

Instantly share code, notes, and snippets.

@tmeasday
Created October 5, 2011 13:36
Show Gist options
  • Save tmeasday/1264438 to your computer and use it in GitHub Desktop.
Save tmeasday/1264438 to your computer and use it in GitHub Desktop.
How to set up a basic premailer test task
class TestController < ApplicationController
def email
prepare_email(params[:type])
PremailerRails::Hook.delivering_email(@mail)
if params[:part] == 'css'
render :template => @html_template, :layout => 'email'
elsif params[:part] == 'html'
render :text => @mail.html_part.body
else
plain = @mail.parts.find {|p| p.content_type =~ /text\/plain/ }
render :text => @mail.text_part.body
end
end
protected
def prepare_email(type)
self.send "prepare_#{type.to_s}".to_sym
end
def prepare_welcome
@user = user
@url = "http://example.com/login"
@html_template = 'user_mailer/welcome.html.erb'
@mail = UserMailer.welcome_email(@user)
end
This code is vaguely based on the action mailer rails guide example. Now try:
/test/email?type=welcome&part=text
This is the plain text part of the email
/test/email?type=welcome&part=css
This is the html part, before premailing, standard css, easier to debug
/test/email?type=welcome&part=html
This is the premailed part, there are sometimes subtle differences.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment