How to Use Carrierwave on Windows

Recommendation from Sean Phillips:

I noticed several users were having an issue regarding Errno::EACCESS around lecture 160. I am happy to report that I believe I found a fix from another helpful user online, seen here: http://blog.pardner.com/2012/01/rails-3-1-carrierwave-s3-heroku/

Uploading to S3 from a Windows machine throws this error because of how Windows handles file permissions. On Unix, you can chown the directory and prevent the error, but that's another story. In development mode, I'm fairly certain that we don't care about hoarding thumbnails that we have to manually delete at a later time.

The fix:

I added the code below to my carrierwave.rb file, under CarrierWave.configure do |config| block. This will check if the environment is in production mode. If not, the code prevents Rails from attempting to delete the file after storage, which is something Windows apparently doesn't like.

if ENV['RAILSENV'] != 'production' config.delete_tmp_file_after_storage = false

I then added the code below to profile_uploader.rb. This points carrierwave to the your cache directory. This -should- be the default directory, and does not throw the EACCES error if not implemented with the code mentioned above. Still always good to specify, just in case.

def cache_dir   "#{Rails.root}/tmp/uploads" end

I hope this helps everyone having this issue! I'm still pretty new to programming (I did your Ruby guide before this course, too) but hopefully this makes enough sense to get people back on the path to completing the course!