Skip to content

Commit d0bc1ff

Browse files
committed
公開統計データは CSV 形式でもダウンロードできるようにした
1 parent 671ed20 commit d0bc1ff

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

app/controllers/dojos_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def show
3535
respond_to do |format|
3636
format.html
3737
format.json { render json: @event_histories }
38+
format.csv { send_data render_to_string, type: :csv }
3839
end
3940
end
4041
end

app/views/dojos/show.csv.ruby

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'csv'
2+
csv_data = CSV.generate do |csv|
3+
csv << %w(開催日 参加数 URL)
4+
@event_histories.each do |event|
5+
csv << [event[:evented_at].strftime("%F"), event[:participants], event[:event_url]]
6+
end
7+
end

app/views/dojos/show.html.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
<a href="<%= events_path %>">近日開催</a>のデータは含まず、<a href="<%= stats_path %>">過去開催</a>のデータを使っています。
2222
<br>
2323
24-
より詳細データは<code><%= link_to dojo_path(@dojo) + '.json', dojo_url(@dojo) + ".json" %></code> でご確認いただけます。
24+
より詳細データは<code><%= link_to dojo_path(@dojo, format: :json), dojo_url(@dojo, format: :json) %></code> でご確認いただけます。
2525
<br>
26+
27+
下記データは <code><%= link_to dojo_path(@dojo, format: :csv), dojo_url(@dojo, format: :csv) %></code> で CSV に変換できます。
2628
</small>
2729
</p>
2830

0 commit comments

Comments
 (0)