2012-10-03 17:38:42 +01:00
|
|
|
class Avatar < ActiveRecord::Base
|
|
|
|
self.abstract_class = true
|
|
|
|
|
|
|
|
MAX_AVATAR_SIZE = 5.megabyte
|
2014-03-11 07:39:25 +00:00
|
|
|
AVATAR_SIZES = { micro: 16, small: 30, medium: 40, big: 81 }
|
2012-10-03 17:38:42 +01:00
|
|
|
|
2013-04-02 16:14:32 +01:00
|
|
|
AVATAR_SIZES_HASH = {}.tap do |styles|
|
|
|
|
AVATAR_SIZES.each do |name, size|
|
2014-03-11 07:39:25 +00:00
|
|
|
styles[name] = { geometry: "#{size}x#{size}#", format: :jpg,
|
|
|
|
convert_options: '-strip -background white -flatten -quality 70' }
|
2013-04-02 16:14:32 +01:00
|
|
|
end
|
|
|
|
end
|
2014-03-11 07:39:25 +00:00
|
|
|
|
2014-01-21 04:51:49 +00:00
|
|
|
has_attached_file :avatar, styles: AVATAR_SIZES_HASH
|
2014-02-12 15:32:53 +00:00
|
|
|
validates_attachment_size :avatar, less_than_or_equal_to: MAX_AVATAR_SIZE
|
2014-02-10 15:50:22 +00:00
|
|
|
validates_attachment_content_type :avatar, content_type: /\Aimage/
|
2014-02-10 15:54:49 +00:00
|
|
|
validates_attachment_file_name :avatar, matches: [ /(png|jpe?g|gif|bmp|tif?f)\z/i ]
|
2012-10-03 17:38:42 +01:00
|
|
|
end
|