Currently I'm working on a Rails 5.2 application. When I try to display a profile's avatar in a show.html.erb template using variant it doesn't work

<%= image_tag @profile.avatar.variant(resize_to_fit: [100, 100]) %>

I get the followingenter image description here

I'm unable to see the image.

I installed gem 'image_processing', '~> 1.2' in my Gemfile.

Also on application.rb I added config.active_storage.variant_processor = :vips

But still, on the backend I get a 500 error:

Started GET "/rails/active_storage/representations/xxxx/steven.jpeg" for 127.0.0.1 at 2018-09-26 16:33:21 -0400
Processing by ActiveStorage::RepresentationsController#show as JPEG
  Parameters: {"signed_blob_id"=>"xxxxxx", "variation_key"=>"xxxxxx", "filename"=>"steven"}
  ActiveStorage::Blob Load (0.3ms)  SELECT  "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2  [["id", 3], ["LIMIT", 1]]
  ↳ /Users/stevenaguilar/.rvm/gems/ruby-2.2.2/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
  Disk Storage (0.1ms) Checked if file exists at key: variants/7rnyyMpZaqXT4RBNtzDqPFqS/477efe2eb62003af0b5b40ec71c56de636f58f942964d830feeed4057b8718a6 (no)
Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.3ms)

If I edit to <%= image_tag @profile.avatar %> I'm able to see the original image.

here is the Photo model:

 class Profile < ApplicationRecord
  belongs_to :user
  has_one_attached :avatar
 end

Any suggestions?

Can you post your model? Did you forget to put has_one_attached :avatar in your model?

  • it works without .variant is not the model. – Steven Aguilar 17 mins ago

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.