启动了一个全新的Rails 6应用程序,按照入门指南,一切都是全新的。我成功上传了文件,但在显示页面上,img标签只是一个破碎的图像图标,但如果我在新选项卡中打开它,它会显示出来。控制台中未显示错误。
/config/initializers/shorine.rb
require "shrine"
require "shrine/storage/file_system"
Shrine.storages = {
cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"), # temporary
store: Shrine::Storage::FileSystem.new("public", prefix: "uploads") # permanent
}
Shrine.plugin :activerecord # loads Active Record integration
Shrine.plugin :cached_attachment_data # enables retaining cached file across form redisplays
Shrine.plugin :restore_cached_data # extracts metadata for assigned cached filesapp/uploaders/image_uploader.rb
class ImageUploader < Shrine
# plugins and uploading logic
endapp/model/content.rb
class Content < ApplicationRecord
include ImageUploader::Attachment(:image) # adds an `image` virtual attribute
end视图/内容/show.html.erb
<p>
<strong>Image:</strong>
<%= image_tag @content.image_url %>
</p>页面源
<img src="/uploads/efe42a8e0d19d3ffcabd26bcddd71473.mp4">发布于 2020-12-17 03:51:38
我想通了。我从Imgur中提取了我正在测试的"gif“,它实际上是一个mp4,因此不会在"image_tag”中显示。把它改成了"video_tag“,它起作用了。
https://stackoverflow.com/questions/65329291
复制相似问题