unknown attribute 'account_number' for Customer.
def import
Customer.import(params[:file])
redirect_to customers_path, notice: "Customers Imported."
end
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
<%= 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 %>
create_table "customers", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "account_number"
t.string "sla_number"
t.string "mobile_phone"
t.string "work_phone"
t.string "home_phone"
t.string "municipality"
t.string "main_product"
t.string "contract_name"
t.date "contract_from"
t.date "contract_to"
end
def self.import(file)
CSV.foreach(file.path, headers: true, header_converters: :symbol) do |row|
customer_hash = row.to_hash
customer = find_or_create_by!(sla_number: customer_hash[:sla_number])
customer.update(customer_hash)
end
end