S3照片ID问题

时间:2011-11-25 09:15:44

标签: amazon-s3

型号:1

class PromotionPhoto < ActiveRecord::Base
     has_attached_file :photo,
       :styles => {
           :large => "524x257!",
           :xmedium => "435x330!",
           :medium => "329x152!",
           :thumb => "100x100!"
       },
       :storage => :s3,
        :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
        :path => ":attachment/:id/:style.:extension" 
 end

模型2:

class PromotionMenuPhoto < ActiveRecord::Base

        has_attached_file :photo,
       :styles => {
           :thumb => "50x50!"
       },
       :storage => :s3,
        :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
        :path => ":attachment/:id/:style.:extension"
end

promotion_photos

id | photo_file_name | photo_content_type |  photo_file_size 

promotion_menu_photos

id | photo_file_name | photo_content_type |  photo_file_size 

问题:如果我上传促销照片显示正确。但同样的照片显示promotion_menus也。怎么了?你能救我吗?

1 个答案:

答案 0 :(得分:0)

两种型号都有相同的附件路径:

:path => ":attachment/:id/:style.:extension"

在两个模型中,附件名称为photo

更改其中一个模型中的附件名称或路径。

以下是回形针has_attached_file的文档:http://rubydoc.info/gems/paperclip/2.4.5/Paperclip/ClassMethods:has_attached_file