【发布时间】:2018-08-19 17:53:52
【问题描述】:
我正在尝试使用如下所示的强参数创建模型“Post”的实例:
private
def post_params
params.require(:post).permit(:name, {images: []})
end
在我的表单中,这就是我将文件上传到 post_params["images"] 并因此上传到 post.images 的方式:
<%= f.file_field :images, multiple: true %>
但我想对上传按钮应用自定义样式,所以我使用 HTML 构建了一个。但我不知道要输入什么name 属性,以便将其包含在post_params 中。这是我尝试过的:
<input name="images" type="file" multiple="true"/>
<input name="post[images]" type="file" multiple="true"/>
<input name="post['images']" type="file" multiple="true"/>
<input name=":images" type="file" multiple="true"/>
但他们都只是去params["post"]["images"],而不是strong_params。
我可以为 HTML 输入提供什么名称以便将其包含在强参数中?
【问题讨论】:
-
如果您使用
erb版本,则在浏览器中右键单击-> 检查元素。您应该看到它正在生成什么名称。然后你可以手动使用它。
标签: html ruby-on-rails ruby input strong-parameters