Prine’s Blog

Archiv für die Kategorie ‘Ruby on Rails

Ruby problems with Date.parse.. (3 elements of civil date are necessary)

Verfasst von: fedoraswiss in: September 11, 2009

On older machines you get problems using Date.parse. The problem occured on a debian 4.0 machine with Ruby 1.8.5 installed.
Instead of using:
Date.parse(„2008/03/07″)
Use:
Date.strptime(„2008/03/07″, ‘%Y/%m/%d’)

Export .csv mit Ruby on Rails

Verfasst von: fedoraswiss in: August 28, 2008

Folgendes Plugin ‘fastercsv’ muss über GEM installiert werden:
gem install fastercsv
Example Code from rubyonrails.org
require ‘fastercsv’

class ReportController

# example action to return the contents
# of a table in CSV format
def export_users
users = User.find(:all)
stream_csv do |csv|
csv << ["first","last","id","email"]
[...]