Skip to content

Instantly share code, notes, and snippets.

@smtm
Created November 21, 2008 15:38
Show Gist options
  • Save smtm/27461 to your computer and use it in GitHub Desktop.
Save smtm/27461 to your computer and use it in GitHub Desktop.
class LocationsController < ApplicationController
hobo_model_controller
auto_actions :all
require 'csv'
web_method :csvimport
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
end
class Location < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
customerkey :string #b2 #kennung #dnr
name :string #c3
street :string #d4 #adresse
zip :string #e5 #plz
city :string #f6 #ort
tel :string #g7 #t1
tel2 :string #h8 #t2
category :string #i9 #Standortart
access :string #j10 #Zeitung
openinghours :string #k11 #ÖZ #Öffnungszeiten
comment :string #l12 #Kommentare
timestamps
end
belongs_to :task
# --- Hobo Permissions --- #
def creatable_by?(user)
user.administrator?
end
def updatable_by?(user, new)
user.administrator?
end
def deletable_by?(user)
user.administrator?
end
def viewable_by?(user, field)
user.signed_up?
end
def csvimport_callable_by?(user)
user.administrator?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment