File upload without entering the file

require ‘rubygems’
require ‘spreadsheet’
Spreadsheet.client_encoding = ‘UTF-8’
workbook = Spreadsheet.open params[:dump][:excel_file]
sheet = workbook.worksheet ‘database’

I am getting an error if i click on upload button with no file in the
field.

On Wed, Aug 8, 2012 at 4:25 AM, deal bitte [email protected] wrote:

I am getting an error if i click on upload button with no file in the field.

And ? If your code assumes the existence of a param that’s not being
provided, why is that a surprise?

Just check that params[:dump][:excel_file] exists before you use it.

You could also disable the upload button by default and enable it using
javascript only if they enter a value in the field.

if params[:dump][:excel_file].blank?
flash[:notice] = “Please provide a file to upload.”
else
my code

This does not work. I tried it before posting this problem.I have this
piece of code in my controller

Jonan S. wrote in post #1071675:

Just check that params[:dump][:excel_file] exists before you use it.

You could also disable the upload button by default and enable it using
javascript only if they enter a value in the field.