teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

修正

2021/10/09 09:20

投稿

kwtkwt
kwtkwt

スコア21

title CHANGED
File without changes
body CHANGED
@@ -4,13 +4,77 @@
4
4
 
5
5
  Heroku でも日本語を表示できるようにしたい。
6
6
 
7
+
7
- ### コード
8
+ ### 該当のソースコード
8
9
  ```ruby
9
10
  gem 'wicked_pdf'
10
11
  gem 'wkhtmltopdf-binary'
11
12
  ```
13
+ app/controllers/resumes_controller.rb
14
+ ```ruby
15
+ class ResumesController < ApplicationController
16
+
12
17
 
18
+ def show
19
+ @resume = Resume.find(current_user_devise.id)
13
20
 
21
+ @user_devise = UserDevise.find(@resume.user_devise_id)
22
+
23
+ respond_to do |format|
24
+ format.html
25
+ format.pdf do
26
+ render pdf: 'filename', # PDF名
27
+ template: 'resumes/show.html.erb', # viewを対象にする
28
+ orientation: 'Landscape', #  横向き
29
+ page_size: 'A4' # ページサイズ
30
+
31
+ end
32
+ end
33
+ end
34
+
35
+
36
+ ```
37
+ config/routes.rb
38
+ ```ruby
39
+ Rails.application.routes.draw do
40
+
41
+ get 'resumes/show', to: 'resumes#show'
42
+
43
+ end
44
+ ```
45
+ app/views/layouts/pdf_template.html.erb
46
+ ```ruby
47
+ <!DOCTYPE html>
48
+ <html>
49
+ <head>
50
+ <title>Wicked PDF</title>
51
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
52
+ <%= wicked_pdf_stylesheet_link_tag 'application', 'data-turbolinks-track': 'reload' %>
53
+ <%= wicked_pdf_javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
54
+ </head>
55
+ <body>
56
+
57
+ <%= yield %>
58
+
59
+ </body>
60
+ </html>
61
+ ```
62
+ app/views/resumes/show.html.erb
63
+ こちらのhtmlがPDFとして出力されていますが、Heroku で日本語のみ表示されません。
64
+ ```ruby
65
+ <html>
66
+ <head>
67
+
68
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
69
+ </head>
70
+ <body>
71
+ aaaaあああ
72
+
73
+ </body>
74
+ </html>
75
+ ```
76
+
77
+
14
78
  ### 試したこと
15
79
  1
16
80