【问题标题】:Edit a submit btn for nested form编辑嵌套表单的提交 btn
【发布时间】:2018-11-20 21:17:06
【问题描述】:

我想自定义提交文件 btn.为此,我使用了纯 css 技巧。但问题是这并不像编辑之前那样有效。我正在使用 cocoon 将图像作为嵌套文件添加到我的实例中。

我正在改变它(完美运行):

<div class="nested-fields col m4 s6">
    <div class="flat_photo_box">
        <%= f.file_field :image %>
    </div>
</div>

进入这个(部分有效):

<div class="nested-fields col m4 s6">
    <div class="image-upload">
       <label for="file-input<%=f.object.id%>">
         <span class="fa fa-download trash_nested_form"></span>
       </label>
       <%= f.file_field :image, id:"file-input#{f.object.id}" %>
    </div>
</div>

有了这个 css 技巧:

.image-upload > input
{
   display: none;
}
.image-upload > label{
  cursor:pointer;
}

错误 = 我可以创建比我想要的更多的嵌套表单,但回形针只保存我上传到第一个嵌套元素中的最后一张图像。你知道错误可能来自哪里吗

【问题讨论】:

    标签: ruby-on-rails paperclip nested-forms cocoon-gem


    【解决方案1】:

    您将id 分配给file_field,html-id 应该是唯一的。虽然页面将正确呈现,但在表单提交时,只会将一个提交到服务器。而是像这样写你的字段:

    <%= f.file_field :image, class:"file-input#{f.object.id}" %>
    

    为什么要分配一个特定的 id?

    【讨论】:

      猜你喜欢
      • 2014-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-27
      相关资源
      最近更新 更多