Fastercsv date problem

this is my controller:

class ExportController < ApplicationController

example action to return the contents

of a table in CSV format

def curriculumplans
programmes = Programme.find(:all)
degrees = Degree.find(:all)
stream_csv do |csv|
programmes.each do |p|
csv << [p.programme_name]
csv << [“Programme Code:”, p.programme_code]
csv << [“Curriculum Plan Dated:” ,
p.created_at.strftime("%d-%m-%y")]
csv << []
csv << [“Compulsory Courses:”, p.ct_compulsory]
csv << [“Elective Courses:”, p.ct_elective]
csv << [“Major Elective Courses:”, p.ct_majorelective]
csv << [“Minor Elective Courses:”, p.ct_minorelective]
csv << [“Major Minor Courses:”, p.ct_majorminor]
csv << []
csv << [“Course Code”,“Course Name”,“Credit Units”,"'Jul 08","'Jan
09","'Jul 09","'Jan 10",“Last Semester of Presentation”,“Excluded
Combination”,“Grouping”,“Remarks”,“Day”,“Week”,“Term”,“Course Type”]

  degrees.each do |d|
    csv << [d.course.course_code, d.course.course_name,

d.course.creditunit.cu, d.course.jul08, d.course.jan09, d.course.jul09,
d.course.jan10, d.course.lmonth.month + d.course.lyear.year,
d.course.excluded_combination, d.course.grouping, d.course.remark,
d.course.day.day, d.course.week.week, d.course.term.term,
d.coursetype.coursetype]
end
end
end
end

private
def stream_csv
filename = params[:action] + “.csv”

   #this is required if you want this to work with IE
   if request.env['HTTP_USER_AGENT'] =~ /msie/i
     headers['Pragma'] = 'public'
     headers["Content-type"] = "text/plain"
     headers['Cache-Control'] = 'no-cache, must-revalidate,

post-check=0, pre-check=0’
headers[‘Content-Disposition’] = “attachment;
filename=”#{filename}""
headers[‘Expires’] = “0”
else
headers[“Content-Type”] ||= ‘text/csv; charset=iso-8859-1;
header=present’
headers[“Content-Disposition”] = “attachment;
filename=”#{filename}""
end

  render :text => Proc.new { |response, output|
    csv = FasterCSV.new(output, :row_sep => "\r\n")
    yield csv
  }
end

end

  1. somehow the “Jul 08”, “Jan 09”, “Jul 09”, “Jan 10” column names does
    not appear as i’ve typed in the excel file

it appears as 8-Jul, 9-Jan, 9-Jul, 10-Jan instead.

  1. also for the “Last Semester of Presentation” >> u.lmonth.month +
    u.lyear.year

it comes out as eg. Feb-09 or Jan-14 (it’s supposed to come out like
“Jan 2004”)

in the database, lyear.year is stored in full (2004, 2014)

how do i change the controller such that the excel csv will stop messing
with my dates?

(i’m using the plugin fastercsv)
thank you in advance!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs