getting rails 3.1 + carrierwave + S3 + heroku working

Carrierwave is a drop-dead-simple way to add image uploading to your rails app. And even using windows XP for a development box (which can make adding new gems troublesome from time to time), the process was fairly smooth.

The railscast for carrierwave is a good start.

To add S3 support, we followed the guidelines in the carrierwave readme file.

To make it work at heroku, per the carrierwave instructions, we added this to our app/uploaders/WHATEVER.rb file:

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

The only ‘gotcha’ we ran into was a Errno::EACCES permissions error when running locally. (It is related to deleting the local tmp file after the file is uploaded to S3. It only happens on windows development boxes, and it causes your form update to fail, although the file IS uploaded correctly to S3.) The fix for that is to disable the delete-temp-after-upload process, which for a development box is no big deal. The fix is described in a carrierwave git issue, and consists of adding the following in your app/uploaders/WHATEVER.rb file:


CarrierWave.configure do |config|
    # hack fix for windows machine due to tmp file permission error
     # per https://github.com/jnicklas/carrierwave/issues/220/
     if ENV['RAILS_ENV'] != 'production'
          config.delete_tmp_file_after_storage = false
     end

This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to getting rails 3.1 + carrierwave + S3 + heroku working

  1. RyanonRails says:

    The mac users on the project I’m on didn’t have a problem and I was stuck.

    Thanks for the quick fix. I can deal with a couple of temp files sitting around.

  2. John Timms says:

    Thanks! This solved what was becoming an incredibly insufferable and hard-to-research issue for me!