lib/SimpleCSVUploder.rb in SimpleCSVUploder-0.1.1 vs lib/SimpleCSVUploder.rb in SimpleCSVUploder-0.1.2

- old
+ new

@@ -1,8 +1,10 @@ require "SimpleCSVUploder/version" module SimpleCSVUploder + attr_accessor :file + def initialize(params = {}) @file = params.delete(:file) super if @file self.filename = sanitize_filename(@file.original_filename) @@ -29,10 +31,12 @@ end end NUM_BYTES_IN_MEGABYTE = 1048576 def file_size_under_one_mb - if (@file.size.to_f / NUM_BYTES_IN_MEGABYTE) > 1 - errors.add(:file, 'File size cannot be over one megabyte.') + if !@file.nil? + if (@file.size.to_f / NUM_BYTES_IN_MEGABYTE) > 1 + errors.add(:file, 'File size cannot be over one megabyte.') + end end end end