解決しました。下部の編集を参照してください。
私の3.1Railsアプリでは、次のようなPDFを生成しています。
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
次に、Paperclipを使用してアップロードすることにより、生成されたPDFをS3に保存しようとしています。
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
しかし、それは私に与えています"\x9C" from ASCII-8BIT to UTF-8
Paperclipを使用してこの生成されたPDFをS3にアップロードするにはどうすればよいですか?Herokuを使用しているため、一時ファイルをサーバーに保存してからアップロードすることはできません。
////解決しました
ああ、私の悪い、あなたはルートでセッションの期間中ファイルを保存することができ ます。
したがって、これは機能します。
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