Uploading pdf

I am trying to upload the pdf using file io operations, i can select the file but when i click on the upload button it is not uploading the file here is my model

class DataFile < ActiveRecord::Base     def self.Save(upload)       name = upload['datafile'].original_filename       directory = "public/data"       # create the file path       path = File.join(directory, name)       # write the file       upload_file = File.new(upload['datafile'], 'r').read       File.open(path, 'w') {|f| f.write(upload_file) }

      image = Magick::ImageList.new('path.pdf')       images = Dir['public/data/*.jpg']       imglist = Magick::ImageList.new       imglist.read(*images)       imglist.write('name.pdf')     end   end

here is my controller

class UploadController < ApplicationController   def index     render :file => 'app\views\upload\uploadfile.html.erb'   end   def uploadFile     DataFile.Save(params[:upload])     render :text => "File has been uploaded successfully"   end end

here is my view

<h1>File Upload</h1> <%= form_tag :url=>{:controller=>"upload",:action => 'uploadFile'},:html=>{:multipart => true, :remote => true} do |f|%> <p><label for='upload_file'>Select File</label> :   <%= file_field 'upload', 'datafile' %></p>   <%= submit_tag('Upload')%> <% end%>