我的产品模型是电子商务商店中的商品,并配置了回形针,以便我可以上传产品模型的图像。
当我为产品添加图像时,图像出现在/system/image/../…/拇指和原始的,但当我做
<% for product in @products %>
<%= link_to product.image.url(:original) %>
<% end %>
当我浏览页面时,它出现了断裂的链接(/system/image/missing.png)。类似于做一组缩略图-我试图实现所有的产品图像像一个缩略图。(如。相册)
其他代码包括模型如下:
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
控制器:
def index
@products = Product.all
end
让回形针知道存放/阅读附件的位置。
将以下选项添加到has_attached_file
:
: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"中定义的附件。
其次,你需要添加:
attr_accessible :image, :image_file_name, :image_content_type
我做到了,中提琴!它工作!