Heroku and tmp folder

26 views
Skip to first unread message

Gustavo Caso

unread,
Apr 23, 2014, 10:59:07 AM4/23/14
to rubyonra...@googlegroups.com
In my Rails app I have delayed_job gem to delay all the emails, the problem with this appear when I want to have some attachments in the emails, in development I store then in tmp folder.
I Heroku I thought that might be possible as well but I get the error the there is no file in that folder.

This is my code inside my controller: 

def send_bill
    @sale = Sale.find(params[:id])
    @client = @sale.client
    create_pdf(@sale, @client)
    PdfMailer.delay.send_pdf_info(@client, current_user.email)
    @bill.update(sent: true)
    flash.now.notice = "Bill was sent successfully"
    render :show
 end

The method create_pdf is the one that create the pdf and store it in the tmp folder.

def create_pdf(sale, client, is_bill = true)
    name = is_bill ? "factura.pdf" : "presupuesto.pdf"
    action = is_bill ? "bills/show" : "bills/budget"
    @sale = sale
    @client = client
    @bill = @sale.bills.first if is_bill
    file = File.new("#{Rails.root}/tmp/#{name}", "w+")
    kit = PDFKit.new( render_to_string(action: "#{action}", layout: 'pdf', format: "pdf"), :page_size => 'A4')
    file = kit.to_file(file.path)
 end

Inside my mailer the code is:

def send_pdf_info(client, current_user_email)
    @client = client
    attachments["Factura.pdf"] = File.read(#{Rails.root}/tmp/factura.pdf")

    mail(to: default_to(@client.email), bcc: current_user_email, subject: "Factura Printoria")
end


I'm not able to solve this.
Any help will be really appreciated. 

Hassan Schroeder

unread,
Apr 23, 2014, 11:41:40 AM4/23/14
to rubyonrails-talk
On Wed, Apr 23, 2014 at 7:59 AM, Gustavo Caso <gusta...@gmail.com> wrote:
> In my Rails app I have delayed_job gem to delay all the emails, the problem
> with this appear when I want to have some attachments in the emails, in
> development I store then in tmp folder.
> I Heroku I thought that might be possible as well but I get the error the
> there is no file in that folder.

Heroku does not provide access to a file system.

Look into cloud storage providers, e.g. Amazon S3, Rackspace
Cloud Files, etc.

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

Gustavo Caso

unread,
Apr 23, 2014, 1:28:55 PM4/23/14
to rubyonra...@googlegroups.com
Thanks. I read some more and I'm going to use amazon S3.
  

 
 
Reply all
Reply to author
Forward
0 new messages