Skip to content

Instantly share code, notes, and snippets.

@noahlh
Created November 27, 2012 01:55
Show Gist options
  • Save noahlh/4151893 to your computer and use it in GitHub Desktop.
Save noahlh/4151893 to your computer and use it in GitHub Desktop.
class GiftCertificatesController < ApplicationController
def show(id=nil)
@gift_certificate = GiftCertificate.find(id || params[:id])
render :show
# render :show, :layout => "gift_certificate"
end
def show_pdf(id=nil)
@gift_certificate = GiftCertificate.find(id || params[:id])
res = render_pdf(@gift_certificate)
send_data res, :content_type => 'application/pdf', :disposition => "inline", :filename => "gdc-gift-certificate.pdf"
end
def render_pdf(gift_certificate)
@gift_certificate = gift_certificate
contents = render_to_string :show, :layout => "gift_certificate"
contents.gsub!('/assets/images/', '')
contents.gsub!('/assets/stylesheets/', '')
contents.gsub!('/assets/', '')
puts contents
res = Docverter::Conversion.run do |c|
c.from = "html"
c.to = "pdf"
c.content = contents
c.add_other_file(File.join(Rails.root, "public", ActionController::Base.helpers.asset_path('application.css')))
c.add_other_file(File.join(Rails.root, "public", ActionController::Base.helpers.asset_path('eb-garamond.ttf')))
c.add_other_file(File.join(Rails.root, "public", ActionController::Base.helpers.asset_path('lamborghini.png')))
c.add_other_file(File.join(Rails.root, "public", ActionController::Base.helpers.asset_path('bentley.png')))
c.add_other_file(File.join(Rails.root, "public", ActionController::Base.helpers.asset_path('ferrari.png')))
c.add_other_file(File.join(Rails.root, "public", ActionController::Base.helpers.asset_path('aston-martin.png')))
c.add_other_file(File.join(Rails.root, "public", ActionController::Base.helpers.asset_path('porsche.png')))
c.add_other_file(File.join(Rails.root, "public", ActionController::Base.helpers.asset_path('gdc-logo.png')))
end
res
end
def send_email_confirmation(id=nil)
@gift_certificate = GiftCertificate.find(id || params[:id])
GiftCertificateMailer(@gift_certificate).confirm_email.deliver
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment