Created
November 21, 2008 15:27
-
-
Save smtm/27456 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#location controller | |
require 'csv' | |
web_method :csvimport do | |
def csvimport | |
unless params[:dump].nil? | |
@parsed_file=CSV::Reader.parse(params[:dump][:file]) | |
n=0 | |
@parsed_file.each do |row| | |
loc=Location.new | |
#row[0] is the first column, this is an array | |
loc.customerkey =row[1] | |
loc.name =row[2] | |
loc.street =row[3] | |
loc.zip =row[4] | |
loc.city =row[5] | |
loc.tel =row[6] | |
loc.tel2 =row[7] | |
loc.category =row[8] | |
loc.access =row[9] | |
loc.openinghours=row[10] | |
loc.comment =row[11] | |
if loc.save | |
n=n+1 | |
GC.start if n%50==0 | |
end | |
flash.now[:message]="CSV import erfolgreich, #{n} neue Datensätze wurden hinzugefügt" | |
end | |
@locations = Location.find :all | |
redirect_to(:controller =>"locations", :action =>"index") | |
end | |
end | |
## Location Model | |
def csvimport_callable_by?(user) | |
user.administrator? | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment