diff --git a/Gemfile b/Gemfile index 2222e06..d0fe369 100755 --- a/Gemfile +++ b/Gemfile @@ -98,3 +98,4 @@ gem "seed_dump", "~> 0.5.3" #gem "themes_for_rails", :git=> 'git://github.com/lucasefe/themes_for_rails.git' gem 'themes_for_rails' +gem 'rubyzip' \ No newline at end of file diff --git a/app/controllers/lvas_controller.rb b/app/controllers/lvas_controller.rb index 8ad623e..916916e 100755 --- a/app/controllers/lvas_controller.rb +++ b/app/controllers/lvas_controller.rb @@ -1,5 +1,6 @@ class LvasController < ApplicationController # GET /lvas + require 'zip' before_filter :load_toolbar, :only => [:show] load_and_authorize_resource def index @@ -9,7 +10,34 @@ class LvasController < ApplicationController {:hicon=>'icon-list', :text=>I18n.t("modul.list"),:path=>moduls_path}, {:hicon=>'icon-list', :text=>I18n.t("lva.list"),:path=>lvas_path}] end - + def beispiel_sammlung + @lva = Lva.find_by_id(params[:id]) + #Attachment name + filename = 'beispiel_sammlung_' + @lva.lvanr.to_s + '_' + l(Date.today).to_s + '.zip' + temp_file = Tempfile.new(filename) + begin + #This is the tricky part + #Initialize the temp file as a zip file + Zip::OutputStream.open(temp_file) { |zos| } + #Add files to the zip file as usual + Zip::File.open(temp_file.path, Zip::File::CREATE) do |zip| + #Put files in here + i=1 + @lva.beispiele.each do |bsp| + zip.add(i.to_s + '_' + File.basename(bsp.beispieldatei.current_path), bsp.beispieldatei.current_path) + i = i + 1 + end + + end + #Read the binary data from the file + zip_data = File.read(temp_file.path) + send_data(zip_data, :type => 'application/zip', :filename => filename) + ensure + #Close and delete the temp file + temp_file.close + temp_file.unlink + end + end # GET /lvas/1 def show diff --git a/app/views/lvas/show.html.erb b/app/views/lvas/show.html.erb index 8d36956..01fe5ba 100755 --- a/app/views/lvas/show.html.erb +++ b/app/views/lvas/show.html.erb @@ -23,6 +23,7 @@

Beispiele

+ <%= link_to t("beispiel.zip") , beispiel_sammlung_lva_path(@lva), class: :linkbox %> <% @lva.beispiele.each do |b| %> <%= render b%> <% end %> diff --git a/config/locales/studien_public.de.yml b/config/locales/studien_public.de.yml index 3e12e8c..cfe7e8b 100644 --- a/config/locales/studien_public.de.yml +++ b/config/locales/studien_public.de.yml @@ -16,6 +16,7 @@ de: beschreibung: "Keine Beschreibung vorhanden" beispiel: add: "Beispiel hinzufügen" + zip: "Alle Beispiele als ZIP Datei" lecturers: lecturers: "Vortragende" file: @@ -23,3 +24,5 @@ de: semester: ohne: "Ohne Semesterzuordnung" semester: "Semester" + home: + newexamples: "Neueste Beispiele" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2a67d45..1c8dcfc 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -65,6 +65,7 @@ Fetsite::Application.routes.draw do resources :beispiele#, :only=>[:show,:index,:create] resources :lvas do member do + get 'beispiel_sammlung' get 'compare_tiss' get 'load_tiss' end