Ask A Question


You’re not receiving notifications from this thread.

Carrierwave Backgrounder in Rails 5.2?

John Athayde asked in Rails

I have an image uploader on a form, and images upload fine without the background processing. Since moving to Heroku, the larger source images often time out, so I'm looking to move this to a background job. In doing so, I looked at carrierwave_backgrounder since it seemed to cover what I need.

I've found a fork of carrierwave_backgrounder and I've forked it to my own repo. To get it working in 5.2, the author said he had to hardcode the path (,

This fails on store_in_background. Running just process_in_background yields locally processed images in development, but they are not uploaded to S3.

The field in quesiton is issue.image and here's how it's mounted in issue.rb:

# Image attachment via Carrierwave
  mount_uploader :image, ImageUploader
  process_in_background :image
  store_in_background :image
  attr_accessor :image_cache

Here's the output error:

2019-02-24T01:05:33.168Z 43666 TID-oxnydp4bq CarrierWave::Workers::StoreAsset JID-83163770b014d37186118cf9 INFO: start
2019-02-24T01:05:33.545Z 43666 TID-oxnydp4bq CarrierWave::Workers::StoreAsset JID-83163770b014d37186118cf9 INFO: fail: 0.377 sec
2019-02-24T01:05:33.545Z 43666 TID-oxnydp4bq WARN: {"context":"Job raised exception","job":{"class":"CarrierWave::Workers::StoreAsset","args":["Issue","6355","image"],"queue":"carrierwave","retry":true,"jid":"83163770b014d37186118cf9","created_at":1550970333.167957,"enqueued_at":1550970333.168011},"jobstr":"{\"class\":\"CarrierWave::Workers::StoreAsset\",\"args\":[\"Issue\",\"6355\",\"image\"],\"queue\":\"carrierwave\",\"retry\":true,\"jid\":\"83163770b014d37186118cf9\",\"created_at\":1550970333.167957,\"enqueued_at\":1550970333.168011}"}
2019-02-24T01:05:33.545Z 43666 TID-oxnydp4bq WARN: TypeError: no implicit conversion of nil into String
2019-02-24T01:05:33.545Z 43666 TID-oxnydp4bq WARN: /Users/jathayde/Development/Meticulous/carrierwave_backgrounder/lib/backgrounder/workers/store_asset_mixin.rb:40:in `join'

and here's the relevant method from my store_asset_mixin.rb method from my local version of the gem. The line 40 mentioned in the error is the one that starts with @tmp_directory:

      def store_directories(record)
        asset, asset_tmp = record.send(:"#{column}"), record.send(:"#{column}_tmp")
        cache_directory  = File.expand_path(asset.cache_dir, asset.root)
        # @cache_path      = File.join(cache_directory, asset_tmp)
        # # XXX Hardcoded our path here... not ideal..
        @cache_path      = open("{asset_tmp}")
        @tmp_directory   = File.join(cache_directory, asset_tmp.split("/").first)

So asset_tmp is "", yet asset but I have no idea why. Stepping thorugh it with debugger it seems that the record.image is present, but the record.image_tmp column is simply empty.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 79,047+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.