2011-09-01 12 views
5

Rozwiązany, patrz edycja u dołu.Zapisz wygenerowany przez system PDF na S3


W moim 3.1 app szyn mam generowania pdf takiego:

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 

Potem próbuję sklepu, który wygenerował plik PDF na S3, przesyłając z spinacza:

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 

Ale to daje mi "\x9C" from ASCII-8BIT to UTF-8

Jak mogę użyć Paperclip, aby przesłać to wygenerowane pdf do S3? Używam Heroku, więc nie mogę zapisać pliku tymczasowego na serwerze, a następnie go przesłać.

//// rozwiązany

Och, mój zły, ty możestore files for the duration of the session at root.

Tak to działa:

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

będę - trzeba więcej niż rep mam nawet odpowiedzieć, nie mówiąc już zaakceptować własną Q w ciągu 8 godzin od pisania. – snowangel

Odpowiedz

3

Och, mój zły, ty możestore files for the duration of the session at root.

Tak to działa:

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 
Powiązane problemy