I've been facing challenges with customizing the simple form field for image upload (Carrierwave) in my Rails application.
My approach involved inspecting the HTML generated by simple form helpers:
<%= f.input :photo %>
<%= f.input :photo_cache, as: :hidden %>
I then added styling, removed unnecessary fields and icons to achieve the following structure:
<label class="btn file-upload-btn">
<div class="form-group file required event_photo upload-field">
<div class="fileinput fileinput-new input-group" data-provides="fileinput">
Add a photo
<div class="form-control uneditable-input input-name" data-trigger="fileinput">
<i class="fa fa-file fileinput-exists"></i>
<span class="fileinput-filename"></span>
</div>
<div class="input-group-btn" style="display: none;">
<input class="file required file-upload" type="file" name="event[photo]" id="event_photo">
</div>
</div>
</div>
<span style="display:none;">
<%= f.input :photo_cache, as: :hidden %>
</span>
</label>
The button functions correctly - I can select an image and the filename is displayed. However, when I attempt to submit the form, it returns an error stating that the image cannot be blank.
What could I be overlooking here?