Ar-Extensions & FasterCSV

Seems unlikely that noting changed since your original error trace seems highly improbable with the trunk version of the software. what's the backtrace now ? (are you certain it's using the new code and not picking up the old gem?)

Fred

HOLY CRAP!!! IT'S ALIVE!

I think it was picking up the old gem. I restarted the server and it worked! Thank you so much!

I've sent Mel a preview of ar-extensions 0.8.0 gem as well. It looks like this fixes the issue. according to the past few messages. I will look into pushing out an official 0.8.0 gem at or after RailsConf,

Zach Dennis http://www.contintuousthinking.com

I believe that I need to do the same things you guys are discussing here. I need to import employee records from a CSV file. Although I have a little wrinkle in my project. Some of the employee records may already exist, in that case I need to update some of the database elements (hours worked, payrate, etc). I have the CSV file with headers and my database is all setup and currently being updated manually within a rails app. I think I am following your examples but am a little stuck on the FasterCSV params. Can you provide me with the exact code that is in your controller?

Thanks, Norman Moore

Below is the code from my experimental app. It’s not a production-level page. I was doing an experiment to figure out how to do this to scratch and itch.

controller/upload.rb

class UploadController < ApplicationController require ‘ar-extensions’

def index
end

def import_csv
Contact.delete_all if params[:dump][:dump] contactx = FasterCSV.parse(params[:dump][:dump].read.chop, {:headers =>true,:skip_blanks => true}) do |row| contactx << Contact.new( :first_name => row[“First Name”], :middle_name => row[“Middle Address”], :last_name => row[“Last Name”], :email_address => row[“Email Address”], :job_title => row[“Job Title”], :company => row[“Company”], :work_phone => row[“Work Phone”], :home_phone => row[“Home Phone”], :address_line_1 => row[“Address Line 1”], :address_line_2 => row[“Address Line 2”], :city => row[“City”], :us_state_ca_province => row[“US State/CA Province”], :other_state_province => row[“Other State/Province”], :country => row[“Country”], :zip_postal_code => row[“Zip/Postal Code”], :sub_zip_postal_code => row[“Sub Zip/Postal Code”], :notes => row[“Notes”], :custom_field_1 => row[" Custom field 1"], :custom_field_2 => row[" Custom field 2"], :custom_field_3 => row[" Custom field 3"], :custom_field_4 => row[" Custom field 4"], :custom_field_5 => row[" Custom field 5"], :custom_field_6 => row[" Custom field 6"], :custom_field_7 => row[" Custom field 7"], :custom_field_8 => row[" Custom field 8"], :custom_field_9 => row[" Custom field 9"], :custom_field_10 => row[" Custom field 10"], :custom_field_11 => row[" Custom field 11"], :custom_field_12 => row[" Custom field 12"], :custom_field_13 => row[" Custom field 13"], :custom_field_14 => row[" Custom field 14"], :custom_field_15 => row[" Custom field 15"] ) end

  Contact.import contactx
 

 end

@contacts = Contact.find(:all)
respond_to do |format| format.html # index.html.erb format.xml { render :xml => @contacts } end end

end

view/upload/index.html.erb

Upload a data file

<% form_for :dump, :url =>{:controller=>“upload”, :action=>“import_csv”}, :html => { :multipart => “true” } do |f| -%>

<table>
Select a CSV File : <%= f.file_field :dump -%> <%= submit_tag "Submit" -%> <% end -%>

view/upload/import_csv.html.erb

Listing contacts

<% for contact in @contacts %>

<% end %>
Firstname Lastname Email
<%=h contact.first_name %> <%=h contact.last_name %> <%=h contact.email_address %> <%= link_to 'Show', contact %> <%= link_to 'Edit', edit_contact_path(contact) %> <%= link_to 'Destroy', contact, :confirm => 'Are you sure?', :method => :delete %>

<%= link_to ‘Upload new file’, :controller => :upload %>

Melvin,

I just wanted to be able to play with a few fields to see if I could get a few fields imported...it works perfectly! Now I know why I decided to develop in Rails.

Thanks, Norm

Yea, the community is pretty cool