Skip to content

Instantly share code, notes, and snippets.

@r38y
Created February 16, 2010 21:43
Show Gist options
  • Save r38y/305965 to your computer and use it in GitHub Desktop.
Save r38y/305965 to your computer and use it in GitHub Desktop.
# 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