视图将上传的回形针图像显示为/original/missing.png [英] Views shows uploaded paperclip images as /original/missing.png

查看:38
本文介绍了视图将上传的回形针图像显示为/original/missing.png的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有产品模型,它是电子商务商店中的商品,并配置了回形针,我可以上传产品模型的图片.

I have Product model which are items in the e-commerce store and is configured with paperclip to i can upload images for the product model.

当我为产品添加图像时,图像出现在/system/image/../.../.../thumbs 和 original 中,但是当我这样做时

When i add the image for the product, the image appears in /system/image/../.../.../thumbs and original but when i do

 <% for product in @products %>
    <%= link_to product.image.url(:original)  %>

  <% end %>

当我浏览页面时,它出现断开的链接 (/system/image/missing.png).类似于做一组缩略图 - 我试图实现像缩略图一样获取所有产品图像.(例如照片库)

it appears broken links (/system/image/missing.png) when i browse the page. Similar to doing a group of thumbnails - i am trying to achieve to get all the product images out like a thumbnail. (eg. photo gallery)

其他代码包括模型如下:

Other code include model are below:

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

推荐答案

让回形针知道存储/读取附件的位置.

Let the Paperclip know about the location of where to store/read the attachments.

将以下选项添加到 has_attached_file:

:url => "/system/:class/:attachment/:id/:style/:basename.:extension",
:path => ":rails_root/public/system/:class/:attachment/:id/:style/:basename.:extension"

这篇关于视图将上传的回形针图像显示为/original/missing.png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆