After upgrading rmagick from 3.5 to 5.2.0 Carrierwave is sending a error of No Method background_color

133 Views Asked by At

n an old Ruby on Rails project using version 4.2.11 with Ruby 2.7.6, we encountered an issue after upgrading RMagick from version 3.5 to 5.2. Specifically, CarrierWave 1.3.1 stopped working when we used the resize_and_pad method. The error message displayed was:

undefined method `background_color=' for #<ChildrenClass::Uploader72920:BadassMemoryAddress>

We checked the RMagick documentation and found no indication of breaking changes in the update. However, it seems that either RMagick was not properly installed or it does not have the background_color= method.

We are unsure if others have experienced the same error or if anyone has any ideas about what might have caused it.

Note: Downgrading RMagick is not an option for us since my local does not support older versions of the required C libraries.

Thanks, and have a great day!!

  • Downgrading rmagic -> Local didnt work (Mac M1)
  • Rebuild the gemfile -> Multiple gems crashed (old project)
2

There are 2 best solutions below

1
spickermann On

You are trying to run the Carrierwave gem with a version that was released 4 years before the version of the RMagick gem you are using.

Because Carrierwave depends on RMagick I am not surprised that old Carrierwave version might be incompatible with recent RMagick versions.

I suggest using a Carrierwave version that was released after the RMagick version. Because you already wrote that you cannot downgrade RMagick below 5.2, the only option seems to be upgrading Carrierwave to a version that was released after RMagick 5.2 was released, which was on 2023-03-12.

Unfortunately, such a version of Carrierwave does not exist. Therefore, I would try the latest minor versions of the latest major versions, hoping that this issue was already addressed. I would try to upgrade Carrierwave to one of these versions (at the day of writing):

  • 1.3.3 - 2023-02-02
  • 2.2.3 - 2022-11-21
  • 3.0.0.beta - 2022-11-19

Because your Carrierwave version is one major version behind and Carrierwave 3.0 is still in beta, the best option seems to be upgrading Carrierwave to 2.2.3.


General advice

You are still running our application with Ruby on Rails 4.2 which was released more than 8 years ago, it has several well-known security vulnerabilities (see here and here) and it has reached end-of-life more than 6 years ago.

Your old version of Rails only runs with version of Ruby that reached end-of-life and are unmaintained, too. Which means you will not get any bug fixes nor security updates anymore. Soon you will notice that updated gems use newer language features or newer syntax that is not supported by your out-dated Ruby version. And each time you are forced to change the application (for example, when a gem or Ruby itself does not compile on newer hardware or with available OS versions anymore), it will get harder and harder.

When you plan to maintain and run your application any longer, then your higher priority should be to update the application as soon as possible.

Because you are already many years behind, such an upgrade will take some time. I wrote about the preferred upgrade path to the latest Ruby and Ruby on Rails versions in this answer.

0
Thormentium On

I recently solved the issue related to the compatibility of the Carrierwave gem (1.3.1) and RMagick gem (5.2.0), and I wanted to share my solution with you all. By investigating the problem, I found that switching from RMagick 5.2 to MiniMagick 4.12 resolved the issue at hand.

In response to a related question, it seems that using an outdated version of Carrierwave alongside a more recent version of RMagick can result in compatibility problems. Given that Carrierwave relies on RMagick, this outcome isn't entirely surprising.

(Note: If you are utilizing Carrierwave versions 1.3.1 - 1.3.3, it's advisable to stick with RMagick 3.X to avoid issues.)

Please bear in mind that these recommendations are subject to change, so I encourage you to verify the latest releases and ensure their compatibility with your specific project. I hope this information proves helpful!

Additionally, I noticed that the method "resize_and_pad" caused a crash in Carrierwave, it was caused by the absence of the "background_color" that is unavailable in RMagick 5.2,