且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取模型中图像变体的 url(在控制器/视图之外)?主动存储

更新时间:2023-11-28 11:07:40

解决方案:

Rails.application.routes.url_helpers.rails_representation_url(picture_of_car.variant(resize: "300x300").processed, only_path: true)

此处提供了答案.

对于一个变体,您需要使用 rails_representation_url(variant) - 这将构建一个类似于 rails_blob_url 构建的 URL,但专门针对该变体.

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.