app/controllers/activities_controller.rb
def report
    prepare_search_dates
    activities = Activity.list( params[:search] )    
    
    require 'csv'
    
    report = StringIO.new
    minutes = 0 
    ::CSV::Writer.generate(report, ',') do |csv|
      header = ["Name", "Login", "Role", "Date", "Minutes"]
      header << "Comments" if params[:search] and params[:search][:details]
      csv << header
      activities.each do |activity|
        minutes += activity.minutes
	      data = [activity.project.name, activity.user.login, activity.user.role.name, activity.date, activity.minutes]
	      data << activity.comments if params[:search] and params[:search][:details]
        csv << data 
      end
      csv << ["Sum", minutes]
    end

    report.rewind
    send_data(report.read,
      :type => 'text/csv; charset=utf-8; header=present',
      :filename => 'report.csv')
  end
#
# Exports all selected activities to CSV file
# Export is done in-memory basing on conditions in params[:search]
# 

Exports all selected activities to CSV file
Export is done in-memory basing on conditions in params[:search]
Exports all selected activities to CSV file Export is done in - memory basing on conditions in params [ : search ]
def report
    prepare_search_dates
    activities = Activity.list( params[:search] )    
    require 'csv'
    report = StringIO.new
    minutes = 0 
    ::CSV::Writer.generate(report, ',') do |csv|
      header = ["Name", "Login", "Role", "Date", "Minutes"]
      header << "Comments" if params[:search] and params[:search][:details]
      csv << header
      activities.each do |activity|
        minutes += activity.minutes
	      data = [activity.project.name, activity.user.login, activity.user.role.name, activity.date, activity.minutes]
	      data << activity.comments if params[:search] and params[:search][:details]
        csv << data 
      end
      csv << ["Sum", minutes]
    end
    report.rewind
    send_data(report.read,
      :type => 'text/csv; charset=utf-8; header=present',
      :filename => 'report.csv')
  end
def report prepare_search_dates activities = Activity . list ( params [ :search ] ) require 'csv' report = StringIO . new minutes = 0 :: CSV :: Writer . generate ( report , ',' ) do | csv | header = [ "Name" , "Login" , "Role" , "Date" , "Minutes" ] header << "Comments" if params [ :search ] and params [ :search ] [ :details ] csv << header activities . each do | activity | minutes += activity . minutes data = [ activity . project . name , activity . user . login , activity . user . role . name , activity . date , activity . minutes ] data << activity . comments if params [ :search ] and params [ :search ] [ :details ] csv << data end csv << [ "Sum" , minutes ] end report . rewind send_data ( report . read , :type => 'text/csv; charset=utf-8; header=present' , :filename => 'report.csv' ) end
Exports all selected activities to CSV file
Export is done in-memory basing on conditions in params[:search]
Exports all selected activities to CSV file Export is done in - memory basing on conditions in params [ : search ]