Skip to content

Commit aca927f

Browse files
committed
feat: 道場一覧にcounterカラムを追加して/statsとの数値検証を容易に
- HTMLテーブルに支部数(counter)カラムを追加 - CSVファイルに支部数カラムと合計行を追加 - コントローラーで@counter_sumを計算して合計表示 - /statsの累積合計と視覚的に比較可能に これにより、/statsページの支部数合計(sum(:counter))と /dojosページの道場リスト(個別道場数)の違いが明確になる
1 parent 5d57dd5 commit aca927f

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

app/controllers/dojos_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def index
4242
description: dojo.description,
4343
}
4444
end
45+
46+
# counter合計を計算(/statsとの照合用)
47+
@counter_sum = @dojos.sum { |d| d[:counter] }
4548

4649
respond_to do |format|
4750
format.html { render :index } # => app/views/dojos/index.html.erb

app/views/dojos/index.csv.ruby

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ require 'csv'
22

33
csv_data = CSV.generate do |csv|
44
# ヘッダー行
5-
csv << ['ID', '道場名', '都道府県', 'URL', '設立日', '状態']
5+
csv << ['ID', '道場名', '支部数', '都道府県', 'URL', '設立日', '状態']
66

77
# データ行
88
@dojos.each do |dojo|
99
csv << [
1010
dojo[:id],
1111
dojo[:name],
12+
dojo[:counter],
1213
dojo[:prefecture],
1314
dojo[:url],
1415
dojo[:created_at].strftime("%F"),
1516
dojo[:is_active] ? 'アクティブ' : '非アクティブ'
1617
]
1718
end
19+
20+
# 合計行を追加
21+
csv << []
22+
csv << ['合計', "#{@dojos.length}道場", @counter_sum, '', '', '', '']
1823
end

app/views/dojos/index.html.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@
9696
道場名 (ID 番号)
9797
</small>
9898
</th>
99+
<th>
100+
<small>
101+
🏢
102+
<br class='ignore-pc'>
103+
支部数
104+
</small>
105+
</th>
99106
<th>
100107
<small>
101108
🗓
@@ -121,6 +128,9 @@
121128
<% end %>
122129
</small>
123130
</td>
131+
<td style="text-align: center;">
132+
<small><%= dojo[:counter] %></small>
133+
</td>
124134
<td>
125135
<small><%= dojo[:created_at].strftime("%F") %></small>
126136
</td>

0 commit comments

Comments
 (0)