2011-09-01 21 views
5

Çözüldü, bkz. Alttaki düzenleme. Benim 3.1 raylar iseSistem tarafından oluşturulan PDF'yi S3 üzerinde depolayın.


Böyle bir pdf oluşturma ediyorum app:

Sonra
def show 
    @contributor = Contributor.find(params[:id]) 

    respond_to do |format| 
    format.pdf { 
    html = render_to_string(:action => "show.html.erb") 
    kit = PDFKit.new(html) 
    kit.stylesheets << "#{Rails.root}/app/assets/stylesheets/unique/print.css" 
    thepdf = send_data kit.to_pdf, :filename => "blah.pdf", :type => 'application/pdf' 
redirect_to :action => save_to_s3  
} 
end 

Ben Paperclip ile yükleyerek S3 PDF oluşturulan mağazaya çalışıyorum:

def save_to_s3 
    html = render_to_string(:action => "show.html.erb") 
     kit = PDFKit.new(html) 
     kit.stylesheets << "#{Rails.root}/app/assets/stylesheets/unique/print.css" 
     roy = Royarchive.new(:client_id => @contributor.client_id) 
     f = File.open("blah.pdf", 'w+') 
     f.write kit.to_pdf 
     roy.pdf = f 
     roy.save! 
end 

Ama bana bu bana "\x9C" from ASCII-8BIT to UTF-8

Bunu oluşturmak için Paperclip'i nasıl kullanabilirim S3 için pdf? Heroku kullanıyorum, böylece sunucuda geçici bir dosya kaydedemiyorum ve yükleyemiyorum. benim kötü

Ah

çözüldü ////

, sen can store files for the duration of the session at root.

Yani bu çalışır:

def show 
    @contributors = Contributor.where(:client_id => current_user.client_id).paginate(:page => params[:page]) 
    @contributor = Contributor.where(:client_id => current_user.client_id).find(params[:id]) 


    respond_to do |format| 
    format.html 
    format.pdf { 
    html = render_to_string(:action => "show.html.erb") 
    kit = PDFKit.new(html) 
    kit.stylesheets << "#{Rails.root}/app/assets/stylesheets/unique/print.css" 
    send_data kit.to_pdf, :filename => "name.pdf", :type => 'application/pdf' 
    @thepdf = kit.to_file("#{Rails.root}/tmp/name.pdf") 

roy = Royarchive.new(:client_id => @contributor.client_id) 
roy.pdf = @thepdf 
roy.save!  
    } 

end 
end 
+0

I will - sen ben bile yazma 8 saat içinde, kendi Q cevap şöyle dursun, kabul etmek zorunda daha fazla temsilcisi gerekir. – snowangel

cevap

3

Aman kötü, sen canstore files for the duration of the session at root.

Yani bu çalışır:

def save_to_s3 
    html = render_to_string(:action => "show.html.erb") 
    kit = PDFKit.new(html) 
    kit.stylesheets << "#{Rails.root}/app/assets/stylesheets/unique/print.css" 
    thepdf = kit.to_file("#{Rails.root}/tmp/name.pdf") 

    roy = Royarchive.new(:client_id => @contributor.client_id) 
    roy.pdf = thepdf 
    roy.save! 
    redirect_to :action => index 
end 
İlgili konular