Note that there are some explanatory texts on larger screens.

plurals
  1. POCarrierWave and Nested Form Gem Redisplay :: HTML File Input Icon
    primarykey
    data
    text
    <p>I'm using CarrierWave and Nested Form Gem. Using the section titled 'Making uploads work across form redisplays' on the Carrierwave github page(https://github.com/jnicklas/carrierwave) I'm able to successfully store the cache so that even if the user makes a mistake then the file is saved. The first time I hit the page and click "Upload File" it works and shows the name of the file as well as a small thumbnail icon indicating the type of file that has been uploaded.</p> <p>However the file input button is blank upon a redisplay and the icon is gone. However I know it's there because if I submit again with valid information and leave the file input button alone it creates a new resource. Here's a snippet of my code.</p> <pre><code>&lt;%= nested_form_for @resource, :html=&gt;{:multipart =&gt; true } do |f| %&gt; &lt;p&gt; &lt;%= f.label :title %&gt;&lt;br /&gt; &lt;%= f.text_field :title %&gt; &lt;/p&gt; &lt;%= f.fields_for :attachments do |attachment_form| %&gt; &lt;p&gt; &lt;%= attachment_form.label :file %&gt; &lt;% if !attachment_form.object.file.path.blank? %&gt; &lt;% file_info = get_cache_file_info attachment_form.object.file.path %&gt; &lt;%= image_tag(File.join('/tmp/cache/', file_info[:folder])) #THIS DISPLAY CORRECTLY %&gt; &lt;% end %&gt; &lt;%= attachment_form.file_field :file %&gt; &lt;%= attachment_form.hidden_field :file_cache %&gt; &lt;/p&gt; &lt;%= attachment_form.link_to_remove "Remove this attachment" %&gt; &lt;% end %&gt; &lt;%= f.link_to_add "Add attachment", :attachments %&gt; &lt;p&gt;&lt;%= f.submit %&gt;&lt;/p&gt; &lt;% end %&gt; </code></pre> <p>I'm wondering if I have to edit the HTML file input to display the icon or is there some other Rails Way to take care of this. Also the image_tag display correctly, but for my application having users upload text files so the images aren't very helpful.</p> <p>Thanks in advance!</p> <p><b>Update</b> I also tried setting the value of the 'input' tag like so:</p> <pre><code>&lt;%= attachment_form.file_field :file, :value =&gt; "#{File.join(file_info[:folder], '/',attachment_form.object.file.identifier)}" %&gt; </code></pre> <p>and that didn't work either. The value of the 'input' tag is set correctly, but it still shows up as "No file selected"</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload