Add schulden csv voor iepoev

This commit is contained in:
Benjamin Cousaert 2014-12-10 16:17:55 +01:00
parent bbc8901353
commit cb94f2dbb8
9 changed files with 38 additions and 0 deletions

View file

@ -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/

View file

@ -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/

View file

@ -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

View file

@ -0,0 +1,2 @@
module AdminsHelper
end

View file

@ -0,0 +1,5 @@
<%- headers = ['nickname', 'schulden'] -%>
<%= CSV.generate_line headers %>
<%- @users.each do |user| -%>
<%= CSV.generate_line([user.nickname, user.balance]) %>
<%- end -%>

View file

@ -40,6 +40,7 @@
<li><%= link_to "List" , users_path %></li>
</ul>
</li>
<li><%= link_to 'Download schulden', admins_schulden_path(format: :csv) %>/li>
<% end %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Logged in as <%= current_user.nickname %> <b class="caret"></b></a>

View file

@ -12,4 +12,5 @@ Rails.application.routes.draw do
end
resources :products
get 'admins' => 'admins#schulden', as: "admins_schulden"
end

View file

@ -0,0 +1,7 @@
require 'test_helper'
class AdminsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,4 @@
require 'test_helper'
class AdminsHelperTest < ActionView::TestCase
end