From 3049324dd8731b31a8925837289721be02217a18 Mon Sep 17 00:00:00 2001 From: "TAKAHASHI,Toru" Date: Sun, 8 Dec 2019 03:05:44 +0900 Subject: [PATCH] [Phase-24]Add csv export --- app/views/glossary_terms/index.csv.ruby | 19 +++++++++++++++++++ app/views/glossary_terms/index.html.erb | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 app/views/glossary_terms/index.csv.ruby diff --git a/app/views/glossary_terms/index.csv.ruby b/app/views/glossary_terms/index.csv.ruby new file mode 100644 index 0000000..9a28b58 --- /dev/null +++ b/app/views/glossary_terms/index.csv.ruby @@ -0,0 +1,19 @@ +require 'csv' + +CSV.generate(row_sep: "\r\n", encoding: "CP932") do |csv| + column_names = ["name", "name_en", "category", "datatype", "codename", "description", "rubi", "abbr_whole"] + csv << column_names + @glossary_terms.each do |term| + column_values = [ + term.name, + term.name_en, + term.category&.name, + term.datatype, + term.codename, + term.description, + term.rubi, + term.abbr_whole + ] + csv << column_values + end +end diff --git a/app/views/glossary_terms/index.html.erb b/app/views/glossary_terms/index.html.erb index 5d5a996..20056e3 100644 --- a/app/views/glossary_terms/index.html.erb +++ b/app/views/glossary_terms/index.html.erb @@ -23,4 +23,6 @@ <%= render 'index_terms', terms: @glossary_terms %> <% end %> - +<% other_formats_links do |f| %> + <%= f.link_to_with_query_parameters 'CSV' %> +<% end %>