Ruby Rails Imagemagick 图片未显示

Ruby on Rails Imagemagick picture is not showing

我正在使用 Imagemagick 上传图片。我正在尝试显示上传的图片:

<%= image_tag @book.picture.url(:small) %>

或没有 (:small)。

但是只显示图片名称。

我的记录本是这样保存的:

    #<Book id: 27, title: "ccccc", genre: "fffff", language: "ccccc", 
format: nil, summary: "fgreqvger", rating: 0.0, source: "cccc", published:
 1234, created_at: "2016-01-17 16:43:00", updated_at: "2016-01-17 16:43:00", 
file_file_name: "filename.pdf", file_content_type: "application/pdf", 
file_file_size: 309205, file_updated_at: "2016-01-17 16:43:00", 
picture_file_name: "Colorful-Flat-PSD-Template-4.jpg", picture_content_type:
 "image/jpeg", picture_file_size: 73885, picture_updated_at: "2016-01-17 
16:43:00", author: nil>

picture_file_name有什么问题吗?还是带有图像路径?无论如何,我真的看不到指定路径的位置。我怎么知道 rails 实际上是在尝试显示正确的图像,或者我怎么知道图像的存储位置?

鉴于您正在寻求帮助,以下是设置 Paperclip 的方法:

#app/models/book.rb
class Book < ActiveRecord::Base
   has_attached_file :picture, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png", path: ":rails_root/public/system/:attachment/:id/:style/:filename", url: ":rails_root/public/system/:attachment/:id/:style/:filename"
  validates_attachment_content_type :picture, content_type: /\Aimage\/.*\Z/
end

考虑到您已经设置了数据库,以上应该允许您上传文件。显示它可以像你已经做的那样完成;所以我唯一的建议是 您没有正确设置 styles 选项,或者您的 imagemagick 安装有问题。