【问题标题】:Thumb images are not displayed不显示拇指图像
【发布时间】:2017-08-09 12:26:49
【问题描述】:

我正在使用carrierwave 和minimagic gems。这是我的索引视图中显示拇指图像的代码:

<div class="panel-body">
  Quantity  :<%= item.qty %><br>
  Price  : <%= number_to_currency(item.price, unit: "RS " ) %><br>
  <%= image_tag item.image_url(:thumb)%>
</div>

这是Image_uploader中可用的代码:

class ImageUploader < CarrierWave::Uploader::Base
  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick
  include CarrierWave::MiniMagick

  # Choose what kind of storage to use for this uploader:
  storage :file
  # storage :fog

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  version :thumb do
    process :resize_to_fit => [50, 50]
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end

它可以在没有:thumb 的情况下工作;图像按原样显示。

<%= image_tag @item.image_url %>

但无法以拇指格式查看。它会在 localhost 预览中显示图像名称和损坏的图像图标。

请帮我解决这个问题。

【问题讨论】:

  • 图片缩略图是真的创建的吗?
  • 试试这个

标签: ruby-on-rails ruby


【解决方案1】:

使用以下代码块,它可以正常工作。

  <%= image_tag item.image_url(:thumb)%>

【讨论】:

  • 这和我的答案一样...在rails括号中是可选的。
【解决方案2】:

试试这个

<%= image_tag item.thumbnail_url(:thumb) %>

或

<%= image_tag item.avatar.thumb.url %>

去想这个链接,它会帮助你。 reference

【讨论】:

  • 试试这个&lt;%= image_tag @item.image(:thumb).url %&gt;
  • 或者这个&lt;%= image_tag(@item.image_url(:thumb).to_s) %&gt;
  • 试试这个
  • 问题出在我上传的图片上。现在可以正常使用了。顺便说一句,感谢您的支持
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-15
  • 2013-02-02
  • 2022-09-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多