Show name and extension of a file when editing form using carrierwave gem in rails

1

I'm using the gem carrierwave to upload documents in my project, and it works perfect, my problem is when I want to edit the form, having previously saved a document, the button to upload a document or image appears with the caption "No file selected";

How can I do to say the name of the file and its extension, for example doc.pdf ?

I leave the code:

 <div class="form-group">
      <%= f.label :avatar, "Foto de Perfil" %>
      <%= f.file_field :avatar  ,class: "btn btn-info btn-sm"%> 
</div>
    
asked by sandovalgus 07.04.2017 в 14:42
source

1 answer

0

You can not. In fact, that text of the input file is handled by the browser and is different depending on what you use or the language of your system. What you can do is hide the input and manage the attachment through a label or, again, show a text that show the name of the file if you already attached it. Something like:

<div class="form-group">
  <%= f.label :avatar, "Foto de Perfil" %>
  <% if tumodelo.avatar.file.exists? %>
    <%= tumodelo.avatar.file.filename %>
  <% end %>
  <%= f.file_field :avatar  ,class: "btn btn-info btn-sm"%> 
</div>
    
answered by 10.04.2017 в 03:18