質問編集履歴
4
mails_controller の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -54,7 +54,7 @@
|
|
54
54
|
@mail.save
|
55
55
|
|
56
56
|
if params[:attachments]
|
57
|
-
@mail.attachments =
|
57
|
+
@mail.attachments = "#{@mail.id}.jpg"
|
58
58
|
image = params[:attachments]
|
59
59
|
File.binwrite("tmp/tests/#{@mail.id}.jpg", image.read)
|
60
60
|
end
|
3
「mails_controller.rb」の変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -54,7 +54,7 @@
|
|
54
54
|
@mail.save
|
55
55
|
|
56
56
|
if params[:attachments]
|
57
|
-
@mail.attachments =
|
57
|
+
@mail.attachments = params[:attachments].original_filename
|
58
58
|
image = params[:attachments]
|
59
59
|
File.binwrite("tmp/tests/#{@mail.id}.jpg", image.read)
|
60
60
|
end
|
2
`mails_controller.rb` の更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -48,10 +48,16 @@
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def create
|
51
|
+
@mails = Mail.all
|
51
|
-
#
|
52
|
+
# gemをインストールしてxlsxデータを出力できるようにする https://qiita.com/necojackarc/items/0dbd672b2888c30c5a38
|
52
|
-
@mail = Mail.new(dest: params[:dest], subject: params[:subject], body: params[:body]
|
53
|
+
@mail = Mail.new(dest: params[:dest], subject: params[:subject], body: params[:body])
|
53
54
|
@mail.save
|
55
|
+
|
56
|
+
if params[:attachments]
|
54
|
-
|
57
|
+
@mail.attachments ="#{@mail.id}.jpg"
|
58
|
+
image = params[:attachments]
|
59
|
+
File.binwrite("tmp/tests/#{@mail.id}.jpg", image.read)
|
60
|
+
end
|
55
61
|
end
|
56
62
|
end
|
57
63
|
|
1
`app/views/mails/index.html.erb` を追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -83,4 +83,32 @@
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
+
```
|
87
|
+
|
88
|
+
```Ruby
|
89
|
+
<!-- app/views/mails/index.html.erb -->
|
90
|
+
|
91
|
+
<h1>送信内容一覧</h1>
|
92
|
+
<table border="1">
|
93
|
+
<thead>
|
94
|
+
<tr>
|
95
|
+
<th>id</th>
|
96
|
+
<th>送信先</th>
|
97
|
+
<th>タイトル</th>
|
98
|
+
<th>内容</th>
|
99
|
+
<th>添付ファイル</th>
|
100
|
+
<th></th>
|
101
|
+
</tr>
|
102
|
+
</thead>
|
103
|
+
<tbody>
|
104
|
+
<% @mails.each.with_index(1) do |mail, i| %> <!-- theadの上にあったのをここに移した-->
|
105
|
+
<tr>
|
106
|
+
<td><%= i %></td>
|
107
|
+
<td><%= mail.dest %></td>
|
108
|
+
<td><%= mail.subject %></td>
|
109
|
+
<td><%= mail.body %></td>
|
110
|
+
<td><%= mail.attachments %></td>
|
111
|
+
</tr>
|
112
|
+
<% end %> <!-- </table>の下にあったのをここに移した -->
|
113
|
+
</table>
|
86
114
|
```
|