【问题标题】:When we have to use multipart: true in Rails [duplicate]当我们必须在 Rails 中使用 multipart: true [重复]
【发布时间】:2015-03-13 14:23:39
【问题描述】:

谁能告诉我我们何时以及为什么在 Rails 中使用 multipart: true ?


表单中有两个属性

 color:string

 name : string

我想确认不需要 multipart: true,对吗?

【问题讨论】:

  • 我完全不明白你在问什么,请试着说得更清楚一点你想做什么,你做了什么,什么不起作用,我们以什么方式可以帮助你。

标签: ruby-on-rails


【解决方案1】:

multipart: true 在表单中上传文件时使用。

在文件上传时检查documentation

您可以使用 form_tag 和明确的 multipart: true 或简单地使用 form_for

<%= form_tag({action: :upload}, multipart: true) do %>
  <%= file_field_tag 'picture' %>
<% end %>

<%= form_for @person do |f| %>
  <%= f.file_field :picture %>
<% end %>

在您的情况下,您不需要multipart: true,因为您只有属性colorname

【讨论】:

    猜你喜欢
    • 2017-11-05
    • 2011-09-17
    • 1970-01-01
    • 2013-10-20
    • 2022-08-17
    • 1970-01-01
    • 2021-12-12
    • 2017-08-01
    • 2017-08-29
    相关资源
    最近更新 更多