Problem with file_field

I trying to do an upload form, bu the file_field doesnt seem to work as
it should. I can't access the datafile properties...

<% form_for @student,
:url => { :action => "upload_file",:id=> }, :multipart =>
true do |f|%>
  <%= file_field 'upload', 'datafile' %>
  <%= submit_tag "Upload" %>
<% end%>

#method 1
  def upload_file
    student = Student.find(params[:id])
    student.data_files <<[:upload])
    redirect_to :edit

#Method 2
      name = upload['datafile'].original_name
      puts name
      directory = "public/data"
      # create the file path
      path = File.join(directory, name)
      # write the file, "wb") { |f| f.write(upload['datafile'].read) }

undefined method `original_name' for "iPhone intro.pdf":String


All the clues are there for you in the error.
It's saying that the upload[:datafile] field is a String object
(you're expecting a File).
So there's a problem with your form sending strings instead of files.
The thing that does the magic with turning file_fields from being just
another text input is the multipart value on the form, so that's
likely to be the problem.
Low and behold - there's a syntax error in your form definition; it should be :

<% form_for @student,
:url => { :action => "upload_file",:id=> }, :html => { :multipart =>
true } do |f|%>

(looks like you got a bit crossed between the form_tag and form_for methods)

That should now at least upload the file to the server, and let you
get on with the rest of the code.

(you'll save another bug hunt if you change :

Try this.
<%form_tag({:action => 'upload_file'},:id=>,:multipart =>
true) do-%>
   <%= file_field :upload, :datafile%>
   <%= submit_tag "Upload" %>

def upload_file
data = params[:upload]
orig_fileName = data[:datafile].original_filename
filePath = "#{RAILS_ROOT}/public/data/#{orig_fileName}"
file_data = data[:datafile].read,"wb"){ |f| f.write file_data }