Created
May 13, 2010 22:21
-
-
Save mariochavez/400554 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Task < ActiveRecord::Base | |
has_many :assets, :as => :attachable, :dependent => :destroy | |
validate :validate_attachments | |
Max_Attachments = 5 | |
Max_Attachment_Size = 1.megabyte | |
def validate_attachments | |
errors.add_to_base("You should attach at least one file") if assets.nil? | |
return if assets.nil? | |
errors.add_to_base("Too many attachments - maximum is #{Max_Attachments}") if assets.length > Max_Attachments | |
assets.each {|a| errors.add_to_base("#{a.name} is over #{Max_Attachment_Size/1.megabyte}MB") if a.file_size > Max_Attachment_Size} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment