When I submit an image via Carrierwave, and am missing one field (i.e. the title), then the cached image will appear...
<% if @post.avatar? %>
<%= image_tag @post.avatar_url, :style => "width:300px" %>
<%= f.hidden_field :avatar_cache %>
<%= @post.avatar_url %>
<% end %>
However, the :avatar_cache field is empty. When I resubmit the form, none of the image properties move forward, so I have to reselect the image.
The issue is similar to this. CarrierWave not saving upload after form redisplay but there was no answer.
What is happening? Thank you.
For me, the issue was that I had
accepts_nested_attributes_for :avatars, allow_destroy: true, reject_if: lambda { |avatar| avatar[:file].blank? }
So I was rejecting the file because the file wasn't there
It is important to note that the file itself does not persist, but only the file cache. That is why the carrierwave docs suggest:
It might be a good idea to show the user that a file has been uploaded, in the case of images, a small thumbnail would be a good indicator:
Check if you have an attr_accessor
declaration for avatar_cache
in your model. I added it by accident instead of attr_accessible
(as mentioned in their docs) and it overrode the methods generated by CarrierWave.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With