Created
February 16, 2010 21:43
-
-
Save r38y/305965 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
# two-step processing of avatars. | |
class User < ActiveRecord::Base | |
has_attached_file :avatar, | |
:default_url => "/images/:attachment/:style-missing.gif", | |
:styles => { :medium => "200x200#", | |
:thumb => "55x55#" }, | |
:storage => 's3', | |
:s3_credentials => File.join(RAILS_ROOT, 'config', 'app_config.yml'), | |
:bucket => APP_CONFIG[:bucket], | |
:path => APP_CONFIG[:path], | |
:url => APP_CONFIG[:url] | |
has_attached_file :local_avatar, | |
:default_url => "/images/:attachment/:style-missing.gif", | |
:path => ":rails_root/public/system/:attachment/:id/:style/:filename", | |
:url => "/system/:attachment/:id/:style/:filename" | |
def process_avatar! | |
if local_avatar? | |
self.avatar = local_avatar | |
self.local_avatar = nil | |
save | |
end | |
end | |
def avatar_url(style=nil, only_public=true) | |
if !has_public_avatar? && only_public | |
"/images/avatars/#{style}-missing.gif" | |
else | |
(local_avatar? ? local_avatar : avatar).url(style) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment