mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-15 00:36:33 +01:00
first pass at csv import functionality for tracks
This commit is contained in:
parent
d093ba39bd
commit
3450c22e97
9 changed files with 144 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue