Active Storage 正在 HTML 中输出图像元数据

Active Storage is outputting image metadata in HTML

我正在创建一个表单,用户可以在其中更改他们上传的图片。问题是编辑图像的表单显示图像元数据以及已上传的图像。在图像旁边,在 HTML 页面中输出以下内容:

[#<ActiveStorage::Attachment id: 3, name: "image", record_type: "Space", record_id: 1, blob_id: 3, created_at: "2018-08-20 00:52:57">, 

如何防止它显示上述数据?

这是相关代码 html.erb 显示图像的文件

<div>
  <% if @space.image.attached? %>
      <%= @space.image.each do |image| %>
      <%= image_tag image  %>
    <% end %>
  <% end %>
</div>

型号

class Space < ApplicationRecord
  belongs_to :user

  has_many_attached :image

end

控制器

class SpacesController < ApplicationController
  before_action :authenticate_user!, except: [:show]

  def index
    @spaces = current_user.spaces
  end

  def new
    @space = current_user.spaces.build
  end

  def create
    @space = current_user.spaces.build(space_params)
    if @space.save
      redirect_to listing_space_path(@space), notice: "Saved..."
    else
      flash[:alert] = "Something went wrong..."
      render :new
    end
  end

  def show
  end

  def update
    if @space.update(space_params)
      flash[:notice] = "Saved!"
    else
      flash[:notice] = "Something went wrong. Please check your submission and try again."
    end
      redirect_back(fallback_location: request.referer)
  end

  private
    def space_params
        params.require(:space).permit(:name, :description, image: [])
    end

end

开启:

<%= @space.image.each do |image| %>

删除<%后的=

在 ERB 标签上,等号将打印该行的结果。它正在图像对象上打印 .inspect

对于使用 haml 和 运行 的人来说:

= @user.images.each do |image|
    = image_tag image.variant(resize_to_limit: [300, 220])

变成

# replace = sign
- @user.images.each do |image|
    = image_tag image.variant(resize_to_limit: [300, 220])