简体   繁体   English

带有编辑表单和file_field的Carrierwave Rails(未选择文件)

[英]Carrierwave Rails with Edit Form and file_field (No file selected)

When my edit view loads, all my fields are populated with the record detail, but the file_field shows "No file Selected" next to the browse button. 加载我的编辑视图时,我的所有字段都会填充记录详细信息,但file_field会在浏览按钮旁边显示“No file Selected”。 I would prefer that is show the record file name instead. 我宁愿显示记录文件名。 Why does it not show that a file that was uploaded? 为什么不显示上传的文件?

Edit View 编辑视图

<%= form_for @document, :html => {:multipart => true} do |f| %>
 <%= f.error_messages %>

   <p>
       <%= f.label :file, "File" %><br />
       <%= f.file_field :file %><br />
       <%= f.hidden_field :file_cache %><br />
       <%= f.label :name, "name" %><br />
       <%= f.text_field :name %><br />
       <%= f.label :memo, "memo" %><br />
       <%= f.text_area :memo %>
     </p>
       <%= f.hidden_field :folder_id %>
 <p><%= f.submit "Upload" %></p>
<% end %>

I think a good counterquestion is "why should show an uploaded file by default?". 我认为一个很好的反问题是“为什么要默认显示上传的文件?”。
But basically is because security reasons and none of the browsers (yep, nothing to do with rails) is going to allow that, so you must to indicate manually to the user about the uploaded files. 但基本上是因为安全原因而且没有任何浏览器(是的,与rails无关)将允许这样做,所以你必须手动向用户指示上传的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM