This commit is contained in:
albert
2013-03-02 21:23:37 -05:00
parent b3ab52e889
commit 3a262d0d50
3 changed files with 17 additions and 2 deletions

View File

@@ -12,11 +12,24 @@ class Upload < ActiveRecord::Base
before_create :convert_cgi_file
after_destroy :delete_temp_file
validate :uploader_is_not_limited
validate :file_or_source_is_present
module ValidationMethods
def uploader_is_not_limited
if !uploader.can_upload?
raise Error.new(uploader.upload_limited_reason)
self.errors.add(:uploader, uploader.upload_limited_reason)
return false
else
return true
end
end
def file_or_source_is_present
if file.blank? && source.blank?
self.errors.add(:base, "Must choose file or specify source")
return false
else
return true
end
end