Created
June 25, 2009 12:02
-
-
Save vrinek/135810 to your computer and use it in GitHub Desktop.
attachment_fu custom error messages
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 Avatar < ActiveRecord::Base | |
has_attachment :content_type => :image, | |
:storage => :file_system, | |
:max_size => 500.kilobytes, | |
:resize_to => 'c128x128', | |
:thumbnails => {:tiny => 'c24x24', :small => "c48x48"} | |
validates_as_attachment | |
after_validation :greeklize_attachment_errors | |
def greeklize_attachment_errors | |
add_attachment_errors({ | |
:content_type => "Το αρχείο δεν είναι εικόνα", | |
:size => "Το αρχείο είναι πολύ μεγάλο (μέγιστο 500KB)" | |
}) | |
end | |
def add_attachment_errors(e) | |
unless errors.empty? | |
previous = self.errors.clone | |
self.errors.clear | |
e.stringify_keys! | |
e.keys.each{|k| | |
self.errors.add k.to_s, e[k].to_s if e[k] and previous.on(k) | |
} | |
previous.each{|a,m| | |
self.errors.add a, m unless e.keys.include?(a) | |
} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment