Rails4 : How do I display and edit uploaded file using carrierwave?

谁说我不能喝 提交于 2019-12-06 06:05:25

I had came up with the same problem earlier but didn't found any solution. What i did is here

<%= form_for(@article) do |f| %>
  <div class="field">
    <%= f.text_area :content, placeholder: "Compose new article..." %>
    <%= f.fields_for :photos, @article.photos do |p| %>
      <%= p.hidden_field :article_id %>
      <%= p.label :image %>
      <% if p.object.image %>
        <%= image_tag p.object.image.url %>
        <p><%= p.object.image.file.filename %></p>
      <% end %>
      <%= p.file_field :image %>
    <% end %>
  </div>
  <%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>

Even if you try to set the image file name to file_field via js , you will get following error

Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!