first pass at csv import functionality for tracks

This commit is contained in:
Darren Cato 2013-07-21 13:37:35 -04:00
parent d093ba39bd
commit 3450c22e97
9 changed files with 144 additions and 4 deletions

View file

@ -137,6 +137,22 @@ class Project < ActiveRecord::Base
@age_in_days ||= (Date.today - created_at.to_date + 1).to_i
end
def self.import params, user
count = 0
CSV.foreach(params[:file], headers: true) do |row|
unless find_by_name_and_user_id row[params[:name].to_i], user.id
project = new
project.name = row[params[:name].to_i]
project.user = user
project.description = row[params[:description].to_i] if row[params[:description].to_i].present?
project.state = 'active'
project.save!
count += 1
end
end
count
end
end
class NullProject