Views shows uploaded paperclip images as /original/missing.png
我有产品模型,该模型是电子商务商店中的商品,并且配置了回形针,可以上传产品模型的图像。
当我为产品添加图像时,图像会显示在/system/image/../.../.../thumbs和原始图像中,但当我这样做时
1 2 3 4 | <% for product in @products %> <%= link_to product.image.url(:original) %> <% end %> |
当我浏览页面时,它显示断开的链接(/system/image/missing.png)。类似于制作一组缩略图-我正在尝试实现将所有产品图像都像缩略图一样显示出来。 (例如照片库)
其他包含模型的代码如下:
1 2 3 4 5 6 7 8 9 | class Product < ActiveRecord::Base attr_accessible :name, :price, :image has_attached_file :image, :styles => { :medium =>"238x238>", :thumb =>"100x100>" } do_not_validate_attachment_file_type :image end |
控制器:
1 2 3 | def index @products = Product.all end |
让回形针知道存储/阅读附件的位置。
将以下选项添加到
1 2 | :url =>"/system/:class/:attachment/:id/:style/:basename.:extension", :path =>":rails_root/public/system/:class/:attachment/:id/:style/:basename.:extension" |
答案是有人偶然发现了这个问题。
您将需要生成回形针迁移。
rails g回形针模型附件(例如:rails g回形针用户头像)-"附件"是您在" has_attached_file"中定义的附件。
其次,您需要添加:
1 | attr_accessible :image, :image_file_name, :image_content_type |
我做到了,中提琴!它奏效了!