gpt4 book ai didi

ruby-on-rails - 无法使用 ActiveStorage image_processing gem 的变体显示图像

转载 作者:行者123 更新时间:2023-12-02 20:15:28 25 4
gpt4 key购买 nike

目前我正在开发 Rails 5.2 应用程序。当我尝试在 show.html.erb 中显示个人资料的头像时模板使用variant它不起作用

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

我得到以下enter image description here

我看不到图像。

我安装了gem 'image_processing', '~> 1.2'在我的 Gemfile 中。

同时在 application.rb我添加了 config.active_storage.variant_processor = :vips

但是,在后端我仍然收到 500 错误:

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)

如果我编辑为<%= image_tag @profile.avatar %>我能够看到原始图像。

这里是Photo型号:

 class Profile < ApplicationRecord
belongs_to :user
has_one_attached :avatar
end

有什么建议吗?

最佳答案

您使用的Rails版本是5.2,该版本的ActiveStorage没有variant_processor选项。

resize_to_fit 是属于image_processing 的选项。您安装了 gem,但处理器固定为 mini_magick。请参阅:https://github.com/rails/rails/blob/v5.2.3/activestorage/app/models/active_storage/variant.rb#L117

如果您想保留5.2版本,您应该遵循mini_magick提供的选项。请参阅:https://api.rubyonrails.org/classes/ActiveStorage/Variation.html

如果您更喜欢使用 image_processing 来享受便捷的选项,您应该将 Rails 版本升级到 >= 6。

关于ruby-on-rails - 无法使用 ActiveStorage image_processing gem 的变体显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52525696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com