前提・実現したいこと
wicked_pdf を使用して、PDFを出力したいが、Heroku で404が返ってきて、PDFが出力されません。
ローカルでは表示できます。
Heroku でも同じように出力したいです。
発生している問題・エラーメッセージ・ログ
ログをみると、ローカルでは正常にレンダリングされていることがわかります。
Heroku
2021-10-08T06:26:20.062279+00:00 app[web.1]: I, [2021-10-08T06:26:20.062201 #13] INFO -- : [294f0711-ea7a-45ba-b3f3-badcd2a2bdc3] Started GET "/resumes/show.pdf" for 60.66.62.161 at 2021-10-08 06:26:20 +0000 2021-10-08T06:26:20.062873+00:00 app[web.1]: I, [2021-10-08T06:26:20.062829 #13] INFO -- : [294f0711-ea7a-45ba-b3f3-badcd2a2bdc3] Processing by ResumesController#show as PDF 2021-10-08T06:26:20.066775+00:00 app[web.1]: D, [2021-10-08T06:26:20.066698 #13] DEBUG -- : [294f0711-ea7a-45ba-b3f3-badcd2a2bdc3] UserDevise Load (1.6ms) SELECT "user_devises".* FROM "user_devises" WHERE "user_devises"."id" = $1 ORDER BY "user_devises"."id" ASC LIMIT $2 [["id", 8], ["LIMIT", 1]] 2021-10-08T06:26:20.068986+00:00 app[web.1]: D, [2021-10-08T06:26:20.068907 #13] DEBUG -- : [294f0711-ea7a-45ba-b3f3-badcd2a2bdc3] Resume Load (1.2ms) SELECT "resumes".* FROM "resumes" WHERE "resumes"."id" = $1 LIMIT $2 [["id", 8], ["LIMIT", 1]] 2021-10-08T06:26:20.069521+00:00 app[web.1]: I, [2021-10-08T06:26:20.069486 #13] INFO -- : [294f0711-ea7a-45ba-b3f3-badcd2a2bdc3] Completed 404 Not Found in 7ms (ActiveRecord: 2.8ms) 2021-10-08T06:26:20.069881+00:00 app[web.1]: F, [2021-10-08T06:26:20.069850 #13] FATAL -- : [294f0711-ea7a-45ba-b3f3-badcd2a2bdc3] 2021-10-08T06:26:20.069904+00:00 app[web.1]: F, [2021-10-08T06:26:20.069884 #13] FATAL -- : [294f0711-ea7a-45ba-b3f3-badcd2a2bdc3] ActiveRecord::RecordNotFound (Couldn't find Resume with 'id'=8): 2021-10-08T06:26:20.069920+00:00 app[web.1]: F, [2021-10-08T06:26:20.069904 #13] FATAL -- : [294f0711-ea7a-45ba-b3f3-badcd2a2bdc3] 2021-10-08T06:26:20.069945+00:00 app[web.1]: F, [2021-10-08T06:26:20.069928 #13] FATAL -- : [294f0711-ea7a-45ba-b3f3-badcd2a2bdc3] app/controllers/resumes_controller.rb:31:in `show' 2021-10-08T06:26:20.070332+00:00 heroku[router]: at=info method=GET path="/resumes/show.pdf" host=job-offer-rkrk.herokuapp.com request_id=294f0711-ea7a-45ba-b3f3-badcd2a2bdc3 fwd="60.66.62.161" dyno=web.1 connect=0ms service=9ms status=404 bytes=1966 protocol=https 2021-10-08T06:26:20.911231+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=job-offer-rkrk.herokuapp.com request_id=6bd240c9-4de4-4217-b7c0-c97530d8551d fwd="60.66.62.161" dyno=web.1 connect=0ms service=1ms status=200 bytes=207 protocol=https
ローカル
Started GET "/resumes/show.pdf" for 127.0.0.1 at 2021-10-08 15:41:33 +0900 Processing by ResumesController#show as PDF UserDevise Load (6.9ms) SELECT "user_devises".* FROM "user_devises" WHERE "user_devises"."id" = ? ORDER BY "user_devises"."id" ASC LIMIT ? [["id", 5], ["LIMIT", 1]] Resume Load (0.5ms) SELECT "resumes".* FROM "resumes" WHERE "resumes"."id" = ? LIMIT ? [["id", 5], ["LIMIT", 1]] UserDevise Load (0.4ms) SELECT "user_devises".* FROM "user_devises" WHERE "user_devises"."id" = ? LIMIT ? [["id", 5], ["LIMIT", 1]] Rendering resumes/show.html.erb Rendered resumes/show.html.erb (5.3ms) [wicked_pdf]: ["/Users/rk/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/wkhtmltopdf-binary-0.12.6.5/bin/wkhtmltopdf", "--orientation", "Landscape", "--page-size", "A4", "file:////var/folders/fr/9n6gyk5j0rl7jml3cskzmnxr0000gn/T/wicked_pdf20211008-50602-8n3mcs.html", "/var/folders/fr/9n6gyk5j0rl7jml3cskzmnxr0000gn/T/wicked_pdf_generated_file20211008-50602-njdv6x.pdf"] Rendering text template Rendered text template (0.0ms) Sent data filename.pdf (10.4ms) Completed 200 OK in 6860ms (Views: 9.3ms | ActiveRecord: 7.8ms)
該当のソースコード
app/controllers/resumes_controller.rb
ruby
1class ResumesController < ApplicationController 2 3 4def show 5 @resume = Resume.find(current_user_devise.id) 6 7 @user_devise = UserDevise.find(@resume.user_devise_id) 8 9 respond_to do |format| 10 format.html 11 format.pdf do 12 render pdf: 'filename', # PDF名 13 template: 'resumes/show.html.erb', # viewを対象にする 14 orientation: 'Landscape', # 横向き 15 page_size: 'A4' # ページサイズ 16 17 end 18 end 19 end 20 21
config/routes.rb
ruby
1Rails.application.routes.draw do 2 3 get 'resumes/show', to: 'resumes#show' 4 5end
app/views/layouts/pdf_template.html.erb
ruby
1<!DOCTYPE html> 2<html> 3 <head> 4 <title>Wicked PDF</title> 5 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 6 <%= wicked_pdf_stylesheet_link_tag 'application', 'data-turbolinks-track': 'reload' %> 7 <%= wicked_pdf_javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> 8 </head> 9 <body> 10 11 <%= yield %> 12 13 </body> 14</html>
app/views/resumes/show.html.erb
ruby
1<html> 2 <head> 3 4 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 5 </head> 6 <body> 7 <%=@resume.id%> 8 9 </body> 10</html>
試したこと
Heroku 再起動
https://qiita.com/awakia/items/d53ab583f214703f6afa
補足情報(FW/ツールのバージョンなど)
Rails 5.1.6
heroku/7.59.0 darwin-x64 node-v12.21.0
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。