Skip to content

Commit

Permalink
Got num-fu working for non-nginx uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Tenner committed Mar 10, 2009
1 parent 2709b58 commit ccfcd1e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/num_fu.rb
Expand Up @@ -18,7 +18,6 @@ module ClassMethods
# Performs common validations for attachment models.
def validates_as_attachment
validates_presence_of :size, :content_type, :filename, :original_filename
validate :attachment_attributes_valid?
end

def self.extended(base)
Expand Down Expand Up @@ -51,13 +50,23 @@ def write_to_temp_file(data)
end

def save_to_storage
if File.file?(@temp_path)
if @temp_path && File.file?(@temp_path)
FileUtils.mkdir_p(File.dirname(full_filename))
File.cp(@temp_path, full_filename)
File.chmod(attachment_options[:chmod] || 0744, full_filename)
else
RAILS_DEFAULT_LOGGER.debug "========= no temp path? #{@temp_path}"
end
end

def delete
self.update_attribute(:deleted_at, Time.now)
end

def delete_file
File.delete(self.full_filename) if File.exists?(self.full_filename)
end

protected
def sanitize_filename(filename)
returning filename.strip do |name|
Expand Down

0 comments on commit ccfcd1e

Please sign in to comment.