Topic: Upload CSV to DB Table in Rails 3

I'm a complete Ruby/Rails newby so excuse me if my question is really basic.  I was building my application in Rails 2.3.x and had uploading CSV files to my database working, but when working in Rails 3.x it won't work. Here is the code I had working in 2.3.x. 

In my routes.rb I had the following line:   
map.resources :physicians, :collection => { :upload => :post } 

In my Controller I had:
require 'fastercsv'

def upload
  upload = params[:file]
  logcount=0
  until upload.eof? do
    row = FasterCSV.parse_line(upload.readline.strip)
    Physician.create(:business_name => row[0], :address1 => row[1], :city => row[2], :state => row[3], :zip => row[4], :phone1 => row[5], :fax => row[6], :contact => row[7], :first => row[8], :last=> row[9], :title => row[10], :specialty => row[11])
  logcount += 1
  end
  flash[:notice] = "Successfully added #{logcount} Physicians."
  redirect_to :action => "index"
end

In my index view I had:
<%= link_to 'New physician', new_physician_path %>
<br />
<br />
<% form_tag upload_physicians_path, :multipart => true do %>
  <label for="file">File to Upload</label> <%= file_field_tag "file" %>
  <%= submit_tag %>
<% end %>

How can I get this working in Rails 3?

Thanks in advance

Scott

Last edited by ssipiora (2011-06-04 01:34:43)