diff --git a/app/assets/javascripts/admins.js.coffee b/app/assets/javascripts/admins.js.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/admins.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/admins.css.scss b/app/assets/stylesheets/admins.css.scss new file mode 100644 index 0000000..984fabc --- /dev/null +++ b/app/assets/stylesheets/admins.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the admins controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/admins_controller.rb b/app/controllers/admins_controller.rb new file mode 100644 index 0000000..7bfad91 --- /dev/null +++ b/app/controllers/admins_controller.rb @@ -0,0 +1,12 @@ +require 'csv' +class AdminsController < ApplicationController + def schulden + @users = User.all + respond_to do |format| + format.csv do + headers['Content-Disposition'] = "attachment; filename=\"zeus-schulden\"" + headers['Content-Type'] ||= 'text/csv' + end + end + end +end diff --git a/app/helpers/admins_helper.rb b/app/helpers/admins_helper.rb new file mode 100644 index 0000000..d4f7b34 --- /dev/null +++ b/app/helpers/admins_helper.rb @@ -0,0 +1,2 @@ +module AdminsHelper +end diff --git a/app/views/admins/schulden.csv.erb b/app/views/admins/schulden.csv.erb new file mode 100644 index 0000000..d707805 --- /dev/null +++ b/app/views/admins/schulden.csv.erb @@ -0,0 +1,5 @@ +<%- headers = ['nickname', 'schulden'] -%> +<%= CSV.generate_line headers %> +<%- @users.each do |user| -%> + <%= CSV.generate_line([user.nickname, user.balance]) %> +<%- end -%> diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index ef3b581..60f5119 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -40,6 +40,7 @@
  • <%= link_to "List" , users_path %>
  • +
  • <%= link_to 'Download schulden', admins_schulden_path(format: :csv) %>/li> <% end %>