Luke Scott said over 1 year ago on Importing and Exporting CSV Data :
I've got a situation where I'm trying to import a csv and its telling me Unknown Attribute, though I can see the attribute is there and correct.  I had a look with debugger and checked the contents of the customer and customer_hash and everything looks fine to me.  Yet when you try to update, unknown attribute 'account_number'.  Any thoughts?



Error:
unknown attribute 'account_number' for Customer. 

CustomersController:
def import
  Customer.import(params[:file])
  redirect_to customers_path, notice: "Customers Imported."
end

Customer Model:
  def self.import(file)
    CSV.foreach(file.path, headers: true) do |row|
      customer_hash = row.to_hash
      customer = find_or_create_by!(sla_number: customer_hash['sla_number'])
      customer.update(customer_hash)
    end
  end

Customers index:
 <%= form_tag import_customers_path, multipart: true, class: 'form-inline' do %>
   <%= file_field_tag :file, class: "" %>
   <%= submit_tag "Import CSV", class: "btn btn-info" %>
<% end %>