def uploaded_data=(file_data)
      if file_data.respond_to?(:content_type)
        return nil if file_data.size == 0
        self.content_type = detect_mimetype(file_data)
        self.filename     = file_data.original_filename if respond_to?(:filename)
      else
        return nil if file_data.blank? || file_data['size'] == 0
        self.content_type = file_data['content_type']
        self.filename =  file_data['filename']
        file_data = file_data['tempfile']
      end
      if file_data.is_a?(StringIO)
        file_data.rewind
        set_temp_data file_data.read
      else
        self.temp_paths.unshift file_data.tempfile.path
      end
    end
def uploaded_data=(file_data)
      if file_data.respond_to?(:content_type)
        return nil if file_data.size == 0
        self.content_type = detect_mimetype(file_data)
        self.filename     = file_data.original_filename if respond_to?(:filename)
      else
        return nil if file_data.blank? || file_data['size'] == 0
        self.content_type = file_data['content_type']
        self.filename =  file_data['filename']
        file_data = file_data['tempfile']
      end
      if file_data.is_a?(StringIO)
        file_data.rewind
        set_temp_data file_data.read
      else
        self.temp_paths.unshift file_data.tempfile.path
      end
    end
This method handles the uploaded file object.  If you set the field name to uploaded_data, you don't need
 any special code in your controller.

   <% form_for :attachment, :html => { :multipart => true } do |f| -%>
     <p><%= f.file_field :uploaded_data %></p>
     <p><%= submit_tag :Save %>
   <% end -%>

   @attachment = Attachment.create! params[:attachment]