Untitled
rails
posted: Dec, 9th 2011 | jump to bottom
def upload_csv require 'csv' uploaded_file = params[:csv][:file] logger.info uploaded_file.tempfile CSV.foreach(uploaded_file.tempfile) do |row| if row[2] redirect_to people_path, :notice => 'Import stopped: too many columns' end p = Person.new p.name = row[0].to_s.strip.gsub(/\P{ASCII}/, '') p.email = row[1].to_s.strip.gsub(/\P{ASCII}/, '') p.person_group_id = params[:csv][:person_group_id] p.save end redirect_to people_path, :notice => 'CSV imported.' end
73 views




