Created
March 31, 2010 08:35
-
-
Save cs3b/350094 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# model invoice | |
def store_pdf | |
# this should be constant | |
temp_invoice_file_path = Rails.root.join("html2pdf/invoice.html") | |
File.open(temp_invoice_file_path, 'w') {|f| f.write(markup) } | |
if ENV['OS'] and ENV['OS'].include?("Windows") | |
`xhtml2pdf html2pdf/invoice.html #{filepath}` | |
else | |
`python pisa.py #{temp_invoice_file_path} #{filepath}` | |
end | |
# File.delete(temp_invoice_file_path) | |
filepath | |
end | |
def filepath(extension='pdf') | |
Rails.root.join "html2pdf/invoice_cache/#{filename}.#{extension}" | |
end | |
# controller mail | |
def create | |
params[:mailing][:filepaths] = [[ @invoice.store_pdf, @invoice.filename+".pdf"]] | |
if Mailing.create(params[:mailing]) | |
@invoice.update_attribute(:emailed_at, Time.now) | |
end | |
respond_to do |format| | |
format.html {redirect_to invoicing_invoice_path(@invoice)} | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment