我有3个车型里面应该有与之关联的图片:如何为多个模型设置回形针和关联?
Program.rb
Episode.rb
Gallery.rb
任何人都需要有不同的图像大小。例如:
Program -> 100x100 , 250x400 , 500x400
Episode -> 222x450 , 210x330 , 1000x1200
Gallery -> 100x100 , 500x400 , 1000x1200
首先,我想到了一个polymorphic
协会一个Picture
模型has_attached_file
(曲别针的助手)的就足够了。就像这样:
class Picture < ActiveRecord::Base
has_many :imageable, :polypmorphic=> :true
has_attached_file :image, :styles => {... :program1 => "100x100>", :program2 => "250x400>", :episode1=>"222x450" , :episode2=>"210x330" , :gallery1=>"100x100" , :gallery2=>"500x400" .... }
# There are almost 10 different styles for different models...
end
通过这种方式,我可以用图像就像这样:
但我不认为这是有效的?是吗?
什么是处理这种需求的最佳策略是什么?
我该如何建立我的关联和Paperclip?
例如,为每个模型设置回形针是否更好?
我想收集一个表中的所有图像将是一个很好的做法?
您认为如何?
这应该是一个常见的问题呢?不是吗?
谢谢
非常感谢您考虑我的邮件并回答乔恩的问题。我appriciate它。 – scaryguy