Monday, 26 August 2013

ruby on rails, csv import, created_at attribute won't updates when i import csv file

ruby on rails, csv import, created_at attribute won't updates when i
import csv file

i tried to import a csv file to my database. I need the app takes the
exact created_at attribute from csv file, but it won't work. I see only
Time.now
What i'm doing wrong? Thanx.
The csv import code in the model
def self.import(file, current_user)
allowed_attributes = [ "id","created_at","updated_at"]
@current_user = current_user
CSV.foreach(file.path, headers: true) do |row|
energy = find_by_id(row["id"]) || new
h1 = { "user_id" => @current_user.id }
h2 = row.to_hash.slice(*accessible_attributes)
h3 = h1.merge(h2)
energy.attributes = h3
energy.save!
end
end

No comments:

Post a Comment