【问题标题】:Picture Not Being Uploaded图片未上传
【发布时间】:2018-06-05 00:43:48
【问题描述】:

我一直在尝试在 RoR 中上传图片,但图片没有上传。 我的控制器的代码 sn-p 是

def employee_params_with_pic
    params.require(:employee).permit( :phone, :personal_email, :address, :picture)
  end

我认为上传图片的代码是

<div>
    <%= f.label :Display %>
    <%= f.file_field :picture %>
</div>

当我选择要上传的图片时,结果如下

数据库的空字段被删除。相反,它没有显示任何值

图片没有出现在它应该显示的字段中。

显示图像的视图是

<span class="content">
    <%= image_tag @employee.details.url if @employee.picture? %>
</span>

【问题讨论】:

  • 你的图片栏的字段类型是什么?您是否使用任何 gem 上传图像?
  • 我正在使用以下宝石 gem 'carrierwave'、'1.1.0' gem 'mini_magick'、'4.7.0' gem 'fog-aws'、'2.0.0' gem 'nokogiri' , '1.8.1'
  • picture 列的数据类型是什么?
  • 数据类型为字符串
  • 您是否在Employee 模型中为picture 字段添加了mount_uploader

标签: html css ruby-on-rails sqlite


【解决方案1】:

应该是这样的:

<%= image_tag @employee.picture_url if @employee.picture? %>

【讨论】:

  • 不工作...我的数据库没有显示任何值,甚至没有显示为空
  • 您是否使用aws 存储桶将其存储在本地?
  • using fog-aws gem 正在使用
  • 签入mount_uploader,如果您的storage type
  • mount_uploader :图片,图片上传
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-28
  • 2023-03-26
  • 1970-01-01
相关资源
最近更新 更多