How to display Carrierwave cached thumbnail
carrierwave, ruby-on-rails
Solution
Okay, finally figured it out.
Carrierwave does cache uploads even in cases of validation error. That's what the cache is for, after all. It relieves the user of the need to reupload the file.
Users of the gem (me, the programmer), don't need to worry about how to access the cache. Just include the cache field in the form and attr_accessible and access the image (or whatever file) like normal. Carrierwave will do the rest transparently. So in my case
%td= image_tag post.image.url :thumb
will display the image correctly, either from the store directory or the cache.
Carrierwave on GitHub
Problem
I use Carrierwave to allow users to attach images to their posts. In the list of posts I display the thumbnails (in haml) as follows: ``` %td= image_tag post.image.url :thumb ``` If validation fails when creating a new post I display the cache like this: ``` = image_tag "/#{ImageUploader::cache_dir}/#{post.image_cache}" ``` What I can't figure out is how to display the cached thumbnail. Checking the filesystem confirms that it lives in the same directory as the cached image. I tried ``` = image_tag post.image_cache :thumb ``` but it errors with `wrong number of arguments (1 for 0)`