Por ir al grano, que dijo un dermatólogo, estaba yo con un modelo que soportase archivos anexos y traducciones y decidí tirar de attachment_fu y translate_columns. Para que los archivos anexos fueran traducibles también fue necesario incluir los campos que utiliza attachment_fu y sobreescribir el método public_filename. La cosa quedó más o menos así:
class Attachment < ActiveRecord::Base
has_many :translations, :class_name => 'AttachmentTranslation'
translate_columns :title, :url, :size, :content_type, :filename, :height, :width
has_attachment :content_type => :image, :storage => :file_system, :path_prefix => 'public/uploads/attachments', :max_size => 4.megabytes
def full_filename(thumbnail = nil)
if self.translation && !self.translation.filename.blank?
self.translation.full_filename(thumbnail)
else
file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s
File.join(RAILS_ROOT, file_system_path, *partitioned_path(thumbnail_name_for(thumbnail))) rescue ''
end
end
end
class AttachmentTranslation < ActiveRecord::Base
belongs_to :attachment
has_attachment :content_type => :image, :storage => :file_system, :path_prefix => 'public/uploads/attachment_translations', :max_size => 4.megabytes
end
¡Y listo! Ha sido corto pero intenso. ¡Salud y rocanrol!
Sea tan amable y diga qué le debo
Y yo suelo pagar lo que como y lo que bebo
He comido un pincho de tortilla
Dos bocadillos de morcilla
He acabado un queso de tetilla
Y me niego a fregar la vajilla
Diga qué le debo
Que me diga qué le debo de una vez
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario