[英]Paperclip separate styles
How can i separate styles for different models? 如何区分不同型号的款式?
I have my Photo model
which generate my styles 我有可以生成样式的
Photo model
large:'300x300#',huge:'800x800'
also i have two models witch use this styles 我也有两个女巫使用这个样式
Product
and 和
Post
so i want to use 所以我想用
large style
only for Product
large style
仅适用于Product
and huge style
only for Post
和
huge style
只为Post
product => has_many :photos
post => has_one :photo
photo => belongs_to :post
belongs_to :product
has_attached_file :image, :styles => {large:'300x300#',huge:'800x800'}
Is it possible? 可能吗?
I advice you to separte image by a image model type using STI, and polymorphism, therefore, add imageable_type
, imageable_id
, and type
field to photo model, so: 我建议你使用STI一个图像模型类型,多态separte图像,因此,加
imageable_type
, imageable_id
和type
场照片模式,所以:
app/models/photo.rb : app / models / photo.rb :
class Photo < AR::Base
belongs_to :imageable, polymorphic: true
end
app/models/photos/large_photo.rb : app / models / photos / large_photo.rb :
class LargePhoto < Photo
has_attached_file :image, :styles => { large:'300x300#' }
end
app/models/photos/huge_photo.rb : app / models / photos / huge_photo.rb :
class HugePhoto < Photo
has_attached_file :image, :styles => { huge:'800x800' }
end
app/models/product.rb : app / models / product.rb :
class Product < AR::Base
has_many :large_photos, as: imageable
end
app/models/post.rb : app / models / post.rb :
class Post < AR::Base
has_one :huge_photo, as: imageable
end
BUT for me, will be better to use carrierwave
, rather than paperclip
for this case. 但对我而言,在这种情况下,最好使用
carrierwave
而不是paperclip
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.