【问题标题】:Paperclip loading images from assets/images directory回形针从 assets/images 目录加载图像
【发布时间】:2017-01-07 06:08:45
【问题描述】:

如果图像存储在 assets/images/Garden3.jpeg 中,如何使用回形针 gem 调出图像?我使用 rails 控制台自己添加了记录,以下是数据库中的值:

#<Product id: 1, product_code: "FB_60", product_description: "Fruits: Apple,Orange,Banana Flowers: Zebra, Chrysa...", price: #<BigDecimal:7f9ec73ec430,'0.6E2',9(18)>, product_image_file_name: "Garden3.jpeg", product_image_content_type: "jpeg", product_image_file_size: nil, product_image_updated_at: nil, category_id: 1>

我在目录asset/images/Garden3.jpeg 中有一张图片。产品模型将加载图像并显示图像、价格和详细信息。在我的产品模型中,我有:

class Product < ActiveRecord::Base
  belongs_to :category

  has_attached_file :product_image, styles: { small: "64x64", med: "100x100", large: "200x200" },
    :url => "/system/products/product_images/000/000/:id/:style/:basename.:extension",
    :path => ":rails_root/app/assets/images/:basename:extension"

end

我还允许在控制器中使用参数名称 :product_image。但是,当我运行该应用程序时,除了图像图标之外没有显示任何图像:

我可以知道我该如何处理这个问题吗?感谢并感谢我能得到一些解释以改进它。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 rubygems paperclip


    【解决方案1】:

    即使我在将 Rails 应用程序部署到 Heroku 时也遇到过类似的问题。 经过大量尝试,对我有用的是我尝试删除文件名的扩展名。在你的情况下:

    Save data row as `#<Product id: 1, product_code: "FB_60", product_description: "Fruits: Apple,Orange,Banana Flowers: Zebra, Chrysa...", price: #<BigDecimal:7f9ec73ec430,'0.6E2',9(18)>, product_image_file_name: "Garden3", product_image_content_type: "jpeg", product_image_file_size: nil, product_image_updated_at: nil, category_id: 1>`
    

    希望它对您有用,否则请尝试使用文件扩展名。

    `

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-10
      • 1970-01-01
      • 2012-07-28
      • 1970-01-01
      • 1970-01-01
      • 2021-05-11
      • 1970-01-01
      • 2014-01-10
      相关资源
      最近更新 更多