html - Active Storage 以 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
图像对象上打印。
推荐阅读
- python - 如何在python中用二进制值替换列值?
- r - R中的数据读取
- javascript - ng-repeat angularjs 中的值更改后,ng-class 未更新
- sql-server - 带有 SQL Server 的 Crystal Reports 中的 ADO 错误代码 0x 问题
- video - 代号容器中的一个视频占位符
- swift - deinitialize() 在 swift 5.0 中已过时
- haskell - 如何从haskell中的元组的所有第二个元素中创建一个列表
- r - 宽到长格式:如何在特定列之间进行平均(2 组列)
- flutter - Flutter:从firestore获取子集合的父数据
- java - Intellij IDEA平台设置下项目SDK中ClassPath和SourcePath的区别?