Newer
Older
require 'carrierwave/orm/mongomapper'
include MongoMapper::Document
mount_uploader :image, ImageUploader
xml_accessor :caption
key :caption, String
belongs_to :album, :class_name => 'Album'
timestamps!
validates_presence_of :album
def self.instantiate(params = {})
image_file = params[:user_file].first
photo
after_save :log_save_inspection
validates_true_for :album_id, :logic => lambda {self.validate_album_person}
danielvincent
a validé
before_destroy :ensure_user_picture
key :remote_photo_path
key :remote_photo_name
danielvincent
a validé
def validate_album_person
album.person_id == person_id
end
image.url.nil? ? (remote_photo_path + remote_photo_name) : image.url
self.remote_photo_path = remote_path.slice(0, name_start )
self.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length)
def url(name = nil)
if remote_photo_path
name = name.to_s + "_" if name
person.url.chop + remote_photo_path + "/" + name.to_s + remote_photo_name
danielvincent
a validé
def ensure_user_picture
users = Person.all('profile.image_url' => image.url(:thumb_medium) )
users.each{ |user|
danielvincent
a validé
user.profile.update_attributes!(:image_url => nil)
danielvincent
a validé
end
def thumb_hash
{:thumb_url => image.url(:thumb_medium), :id => id, :album_id => album_id}
end