need help w/ MVC coding of simple use of FasterCSV

I’m new to ROR, so still getting used to the MVC syntax; but think I have a simple example here that I hope someone can tell me what I’m doing wrong (& maybe help someone else by doing so):

All I’m trying to do is upload a CSV file, then parse each row of data in it (the first how contains header data).

Here’s the essential part of my view:

<% form_tag ({:action => ‘process_file’}, :multipart => true) do %> <%= file_field_tag ‘file’ %>

<%= submit_tag "Upload" %>

<% end %>

here’s my controller:

def process_file post = Upload.import(params[:file]) flash[:ok] = “data imported” redirect_to :action => index end

and here’s my model, where I’m not parsing anything yet, just putting a stub message to the screen (can one do that in a model? not sure…), just to see if this part works:

require ‘fastercsv’ … def self.import(file) datafile = FasterCSV.new(params[:file]) n = 0 FasterCSV.foreach(datafile) do |row| puts 'on row '.n n = n+1 end end

However, the error I get when I submit a file is:

You’re referencing params from your model - you don’t have access to that. datafile = FasterCSV.new(params[:file])

should be

datafile = FasterCSV.new(file)

Best Wishes,

Peter

Thanks! That helped…(.now on to the next bug…)

rick