我可以使用此代码(Active Storage)获取模型中的 urlRails.application.routes.url_helpers.rails_blob_path(picture_of_car, only_path: true)
但我需要获取调整大小的 varian 的 urlpicture_of_car.variant(resize: "300x300").processed
例如这个代码Rails.application.routes.url_helpers.rails_blob_path(picture_of_car.variant(resize: "300x300").processed, only_path: true)
扔
NoMethodError (undefined method `signed_id' for #< ActiveStorage::Variant:0x0000000004ea6498 >):
最佳答案
解决方案:Rails.application.routes.url_helpers.rails_representation_url(picture_of_car.variant(resize: "300x300").processed, only_path: true)
已提供答案 here .
for a variant you need to use rails_representation_url(variant) - this will build a url similar to the one that rails_blob_url builds but specifically for that variant.
关于ruby-on-rails - 如何获取模型中图像变体的 url(在 Controller / View 之外)?主动存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53542627/