質問編集履歴
3
追記したものがコードの中に入っていなかったので修正しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -79,7 +79,6 @@
|
|
79
79
|
<%= will_paginate @maildbs %>
|
80
80
|
<!-- @userenter.emailには乱数が格納されている -->
|
81
81
|
<%= link_to 'csv download', "/user/#{@userenter.email}.csv" %>
|
82
|
-
```
|
83
82
|
|
84
83
|
|
85
84
|
|
@@ -94,4 +93,8 @@
|
|
94
93
|
@users.pluck(*columns).each do |u|
|
95
94
|
res << u.join(',')+"\r" # body
|
96
95
|
end
|
97
|
-
res.tosjis
|
96
|
+
res.tosjis
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
```
|
2
index\.csv\.rubyファイルを追記しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -79,4 +79,19 @@
|
|
79
79
|
<%= will_paginate @maildbs %>
|
80
80
|
<!-- @userenter.emailには乱数が格納されている -->
|
81
81
|
<%= link_to 'csv download', "/user/#{@userenter.email}.csv" %>
|
82
|
-
```
|
82
|
+
```
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
# app\views\user\index.csv.ruby
|
89
|
+
|
90
|
+
require 'kconv'
|
91
|
+
columns = [:name, :email, :to, :cc, :bcc]
|
92
|
+
res = ""
|
93
|
+
res << columns.map{|c| User.human_attribute_name c }.join(',')+"\r" # header
|
94
|
+
@users.pluck(*columns).each do |u|
|
95
|
+
res << u.join(',')+"\r" # body
|
96
|
+
end
|
97
|
+
res.tosjis
|
1
上にコードを追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,9 +9,6 @@
|
|
9
9
|
ご教示いただければ幸いです。
|
10
10
|
よろしくお願いいたします。
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
12
|
```Ruby
|
16
13
|
|
17
14
|
表示ページは「/user/XXXXXXXX」でXXXXXXXXを取得し
|
@@ -20,4 +17,66 @@
|
|
20
17
|
<%= link_to 'csv download', '/user/変数/index.csv' %>
|
21
18
|
|
22
19
|
|
20
|
+
```
|
21
|
+
|
22
|
+
```Ruby
|
23
|
+
|
24
|
+
# app\controllers\user_controller.rb
|
25
|
+
|
26
|
+
def check
|
27
|
+
# @idnihaURL末尾の8桁のランダム文字列が格納される(ex. TFMIQWYM)
|
28
|
+
@id = params[:id]
|
29
|
+
@user = User.exists?(email: @id)
|
30
|
+
if @user
|
31
|
+
@userenter = User.find_by(email: @id)
|
32
|
+
# @maildbs = Maildb.all
|
33
|
+
@maildbs = Maildb.paginate(page: params[:page], per_page: 10)
|
34
|
+
|
35
|
+
|
36
|
+
respond_to do |format|
|
37
|
+
format.html
|
38
|
+
format.csv do
|
39
|
+
filename = 'maildbs'
|
40
|
+
headers['Content-Disposition'] = "attachment; filename=\"#{filename}.csv\""
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
render 'user/personal'
|
46
|
+
return
|
47
|
+
else
|
48
|
+
render plain: "存在しないページ"
|
49
|
+
return
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
# routes.rb
|
57
|
+
|
58
|
+
get "user/:id" => "user#check"
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
# app\views\user\personal.html.erb
|
66
|
+
|
67
|
+
<% @maildbs.each do |maildb| %>
|
68
|
+
<div class="maildbs-index-item">
|
69
|
+
<div class="maildbs-right">
|
70
|
+
<%= maildb.date %>
|
71
|
+
<%= maildb.time %>
|
72
|
+
<%= maildb.xxxx %>
|
73
|
+
<%= maildb.xxxx %>
|
74
|
+
</div>
|
75
|
+
</div>
|
76
|
+
<% end %>
|
77
|
+
|
78
|
+
<!-- 各ページへのリンク -->
|
79
|
+
<%= will_paginate @maildbs %>
|
80
|
+
<!-- @userenter.emailには乱数が格納されている -->
|
81
|
+
<%= link_to 'csv download', "/user/#{@userenter.email}.csv" %>
|
23
82
|
```
|