I have a simple csv import functionality and I am getting this error
Can't mass-assign protected attributes: First Name Last Name Email
I am very surprised this is happening since I do have attr_accessible for these fields. Here is my info.rb model code
attr_accessible :email, :fname, :lname
def self.import(file)
CSV.foreach(file.path, headers: true) do |row|
Contact.create! row.to_hash
end
end
My CSV is test.csv (the export is working fine, only the import of data is giving this error)
First Name Last Name Email
John Smith [email protected]
Janen Smith [email protected]