How to override created_at field in model when importing a CSV?
ruby-on-rails-3
Solution
You need to add the desired column to the `attr_accessible`
class Tutorial < ActiveRecord::Base
attr_accessible :created_at
end
Problem
I'm importing a CSV full of waitlist signups into my database with previous created dates, how can I import them while keeping their initial dates vs. having them all show the same date of importing? I get the error: `Rails can't mass-assign protected attributes for id, created_at` The code: ``` csv_file = params[:csv][:file].read csv = CSV.parse(csv_file, :headers => false) csv.each do |row| Model.create!(:email => row[0], :created_at => row[1]) end ```