【问题标题】:Rails 6 shrine image_tag is broken but open in new tab is notRails 6神社image_tag已损坏,但在新标签中打开不是
【发布时间】:2021-03-27 11:16:32
【问题描述】:

使用 Shrine 启动了一个全新的 Rails 6 应用程序,一切都是全新的,跟随入门指南。成功上传文件,但在显示页面上,img 标签只是一个损坏的图像图标,但如果我在新选项卡中打开它,它会显示。控制台中没有显示错误。

/config/initializers/shrine.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 files

app/uploaders/image_uploader.rb

class ImageUploader < Shrine
  # plugins and uploading logic
end

app/models/content.rb

class Content < ApplicationRecord
  include ImageUploader::Attachment(:image) # adds an `image` virtual attribute
end

views/contents/show.html.erb

<p>
  <strong>Image:</strong>
  <%= image_tag @content.image_url %>
</p>

页面来源

<img src="/uploads/efe42a8e0d19d3ffcabd26bcddd71473.mp4">

【问题讨论】:

    标签: ruby-on-rails-6 shrine


    【解决方案1】:

    想通了。我从 Imgur 中提取了我正在测试的“gif”,它实际上是一个 mp4,因此不会显示在“image_tag”中。将其更改为“video_tag”并且它正在工作。

    【讨论】:

      猜你喜欢
      • 2022-11-18
      • 2022-08-13
      • 2018-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多