Uploading Image Crashes Rails 7 App

Rails: 7.0.0
Ruby: 3.0.2

I am trying to follow DHH’s video on the Rails home page. After uploading the file in the rich text editor, when I hit save and go to the index page, it crashes with the following error:

Could not open library 'vips.42': dlopen(vips.42, 5): image not found. (LoadError)

So far, I have followed the steps exactly, as mentioned in the video. What am I missing?



Detailed error stack

Started GET "/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--1f657d3ade676e313a4fe7479aed08bfeb6792f2/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJY0c1bkJqb0dSVlE2RkhKbGMybDZaVjkwYjE5c2FXMXBkRnNIYVFJQUJHa0NBQU09IiwiZXhwIjpudWxsLCJwdXIiOiJ2YXJpYXRpb24ifX0=--d13e181aa4190ab54cad5f2ea09ea49161b404f4/desk.png" for at 2021-12-18 12:25:50 -0800
Processing by ActiveStorage::Representations::RedirectController#show as PNG
  Parameters: {"signed_blob_id"=>"eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--1f657d3ade676e313a4fe7479aed08bfeb6792f2", "variation_key"=>"[FILTERED]", "filename"=>"desk"}
  ActiveStorage::Blob Load (0.3ms)  SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  ActiveStorage::VariantRecord Load (0.3ms)  SELECT "active_storage_variant_records".* FROM "active_storage_variant_records" WHERE "active_storage_variant_records"."blob_id" = ? AND "active_storage_variant_records"."variation_digest" = ? LIMIT ?  [["blob_id", 1], ["variation_digest", "wjqVtOuFppDd1oEBBMUc2TyD8vk="], ["LIMIT", 1]]
  Disk Storage (31.1ms) Downloaded file from key: 1iqxwz1xxeueszanceeh767v0qls
Completed 500 Internal Server Error in 217ms (ActiveRecord: 1.3ms | Allocations: 26344)

#<Thread:0x00007fd233ff9760 /Users/akshay/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/actionpack-7.0.0/lib/action_controller/metal/live.rb:340 run> terminated with exception (report_on_exception is true):
/Users/akshay/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/ffi-1.15.4/lib/ffi/library.rb:145:in `block in ffi_lib': Could not open library 'vips.42': dlopen(vips.42, 5): image not found. (LoadError)
Could not open library 'libvips.42.dylib': dlopen(libvips.42.dylib, 5): image not found
	from /Users/akshay/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/ffi-1.15.4/lib/ffi/library.rb:99:in `map'
	from /Users/akshay/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/ffi-1.15.4/lib/ffi/library.rb:99:in `ffi_lib'
	from /Users/akshay/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/ruby-vips-2.1.4/lib/vips.rb:573:in `<module:Vips>'
	from /Users/akshay/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/ruby-vips-2.1.4/lib/vips.rb:570:in `<main>'
	from /Users/akshay/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
1 Like

Minor comment.

Latest version might not mean anything in a week or year. But presumably 7.0.0

And sorry I can’t help you. But I’ve had various problems with Rails 7 too. And lots has changed during the alpha development and many of the tutorials for don’t quite work. Good luck.

Sometimes the build steps aren’t spelled out. More seem to be built into making a new rails app, but others aren’t.

You need to install vips first


@wanglian Installing VIPS fixed the problem, thank you!

1 Like

hello @software_writer, am using Ubuntu 20.04LTS how do I install VIPS?

@easycoder I haven’t tried this, but the following link might help:

How To Install “libvips” Package on Ubuntu

- AK


thanks a lot, it worked for me

1 Like

hello, I tried adding a live update on the post according to the blog video of dhh but it’s not working for me.

<%= turbo_stream_from @post %> on the post show page and

broadcasts_to :post on the comment model

What’s the specific error you’re getting?

Also, post it as a separate, new question on the forum, instead of adding it here, so other people will also see it.

I’m running into a similar issue with the same Rails and Ruby versions as the original poster. I did get Vips installed, which got me further along, but now I’m running into a new issue. Copying from the console output:

12:36:53 web.1  | Completed 500 Internal Server Error in 27ms (ActiveRecord: 0.4ms | Allocations: 5583)
12:36:53 web.1  | 
12:36:53 web.1  | 
12:36:53 web.1  |   
12:36:53 web.1  | TypeError (no implicit conversion to float from string):
12:36:53 web.1  |   
12:36:53 web.1  | ruby-vips (2.1.4) lib/vips/gvalue.rb:106:in `g_value_set_double'
12:36:53 web.1  | ruby-vips (2.1.4) lib/vips/gvalue.rb:106:in `set'
12:36:53 web.1  | ruby-vips (2.1.4) lib/vips/object.rb:252:in `set'
12:36:53 web.1  | ruby-vips (2.1.4) lib/vips/operation.rb:286:in `set'
12:36:53 web.1  | ruby-vips (2.1.4) lib/vips/operation.rb:464:in `block in call'
12:36:53 web.1  | ruby-vips (2.1.4) lib/vips/operation.rb:456:in `each_index'
12:36:53 web.1  | ruby-vips (2.1.4) lib/vips/operation.rb:456:in `call'
12:36:53 web.1  | ruby-vips (2.1.4) lib/vips/image.rb:229:in `method_missing'

So I’ve got Vips installed, but it’s running into a Type error for some reason. My guess is that it has to do with using an incompatible version of libvips?

I’m running on Fedora 35, Rails 7, Ruby 3.0.1, and Vips 8.11.3

Any advice?

Edit: Thought about it and I should have clarified. This is when trying to render a variant in the view, following along with the steps in the Active Storage guides HERE.

Edit 2: I went ahead compiled and installed the latest libvips release directly from Github to rule out it being a compatibility issue between versions (Fedora includes libvibs 8.11.3, whereas the latest release on git is 8.12.1).

While I didn’t completely verify if that was the issue (I needed to add a lot of libraries for the different filetypes and I’m not patient enough to do that today), I was able to confirm that the issue wasn’t related to issues with my web application and that the issue is stemming from either the version of Vips provided in the Fedora repositories, or an issue with the ruby-vips gem. In the meantime, I’m able to work around this issue by switching Vips out for ImageMagick in config/application.rb by adding this line:

Rails.application.config.active_storage.variant_processor = :mini_magick

This is just a work around in the meantime until this issue is ironed out.

For anyone scrolling by, in general, you will want to use libvips rather than ImageMagick, as this is the standard for Rails going forward. This is a temporary fix that let’s me continue development and I intend to switch it back to libvips once I/upstream gets the issues resolved.


no implicit conversion to float from string means you’re passing a string where ruby-vips is expecting a float.

You’ll need to post a longer stacktrace before we can see the real cause of the error, but this typically happens because old imagemagick code worked with strings for numbers – you can use "400" (ie. the three character string) for an image width, for example. This in turn is because the mini_magick gem works by assembling ImageMagick command lines, so ultimately everything is passed as a string.

ruby-vips works by making direct FFI calls into the libvips binary (there’s no command-line), so numbers really do need to be numbers.

I’d look over your code and check for any numbers being passed as strings. mini_magick will work with numbers too, so it’s a safe change to make.

1 Like

Most of the image transformation guides written for image magick will not work for vips, as the macros they use are different.

The upgrade guide has a full list of every change you need to make from minimagick to vips, as well as the error message that each one will cause. In your case, I think you are trying to resize?

- variant(resize: "100x")
+ variant(resize_to_limit: [100, nil])