質問編集履歴
3
追記したものがコードの中に入っていなかったので修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -160,8 +160,6 @@
|
|
160
160
|
|
161
161
|
<%= link_to 'csv download', "/user/#{@userenter.email}.csv" %>
|
162
162
|
|
163
|
-
```
|
164
|
-
|
165
163
|
|
166
164
|
|
167
165
|
|
@@ -191,3 +189,11 @@
|
|
191
189
|
end
|
192
190
|
|
193
191
|
res.tosjis
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
```
|
2
index\.csv\.rubyファイルを追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -161,3 +161,33 @@
|
|
161
161
|
<%= link_to 'csv download', "/user/#{@userenter.email}.csv" %>
|
162
162
|
|
163
163
|
```
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
# app\views\user\index.csv.ruby
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
require 'kconv'
|
180
|
+
|
181
|
+
columns = [:name, :email, :to, :cc, :bcc]
|
182
|
+
|
183
|
+
res = ""
|
184
|
+
|
185
|
+
res << columns.map{|c| User.human_attribute_name c }.join(',')+"\r" # header
|
186
|
+
|
187
|
+
@users.pluck(*columns).each do |u|
|
188
|
+
|
189
|
+
res << u.join(',')+"\r" # body
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
res.tosjis
|
1
上にコードを追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,12 +20,6 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
23
|
```Ruby
|
30
24
|
|
31
25
|
|
@@ -43,3 +37,127 @@
|
|
43
37
|
|
44
38
|
|
45
39
|
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
```Ruby
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
# app\controllers\user_controller.rb
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
def check
|
52
|
+
|
53
|
+
# @idnihaURL末尾の8桁のランダム文字列が格納される(ex. TFMIQWYM)
|
54
|
+
|
55
|
+
@id = params[:id]
|
56
|
+
|
57
|
+
@user = User.exists?(email: @id)
|
58
|
+
|
59
|
+
if @user
|
60
|
+
|
61
|
+
@userenter = User.find_by(email: @id)
|
62
|
+
|
63
|
+
# @maildbs = Maildb.all
|
64
|
+
|
65
|
+
@maildbs = Maildb.paginate(page: params[:page], per_page: 10)
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
respond_to do |format|
|
72
|
+
|
73
|
+
format.html
|
74
|
+
|
75
|
+
format.csv do
|
76
|
+
|
77
|
+
filename = 'maildbs'
|
78
|
+
|
79
|
+
headers['Content-Disposition'] = "attachment; filename=\"#{filename}.csv\""
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
render 'user/personal'
|
90
|
+
|
91
|
+
return
|
92
|
+
|
93
|
+
else
|
94
|
+
|
95
|
+
render plain: "存在しないページ"
|
96
|
+
|
97
|
+
return
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
# routes.rb
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
get "user/:id" => "user#check"
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
# app\views\user\personal.html.erb
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
<% @maildbs.each do |maildb| %>
|
134
|
+
|
135
|
+
<div class="maildbs-index-item">
|
136
|
+
|
137
|
+
<div class="maildbs-right">
|
138
|
+
|
139
|
+
<%= maildb.date %>
|
140
|
+
|
141
|
+
<%= maildb.time %>
|
142
|
+
|
143
|
+
<%= maildb.xxxx %>
|
144
|
+
|
145
|
+
<%= maildb.xxxx %>
|
146
|
+
|
147
|
+
</div>
|
148
|
+
|
149
|
+
</div>
|
150
|
+
|
151
|
+
<% end %>
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
<!-- 各ページへのリンク -->
|
156
|
+
|
157
|
+
<%= will_paginate @maildbs %>
|
158
|
+
|
159
|
+
<!-- @userenter.emailには乱数が格納されている -->
|
160
|
+
|
161
|
+
<%= link_to 'csv download', "/user/#{@userenter.email}.csv" %>
|
162
|
+
|
163
|
+
```
|