升级到 rails 6.1.3 后,Aws 返回 403 错误image_tag @item.photos.first
。所有变体都显示没有任何错误。
项目.rb
class Item < ApplicationRecord
has_many_attached :photos, dependent: :destroy
end
items_controller
def show
@item = Item.find[params[:id]
end
项目/show.html.erb
<% if @item.photos.attached?%>
<%= image_tag(@item.photos.first,
srcset: [
[url_for(photos_variants(@item.photos.first, 300, 180)), "375w"],
[url_for(photos_variants(@item.photos.first, 500, 300)), "512w"],
[url_for(photos_variants(@item.photos.first, 750, 450)), "768w"],
[url_for(photos_variants(@item.photos.first, 1000, 600)), "1024w"],
[url_for(photos_variants(@item.photos.first, 1500, 900)), "1980w"]
],
sizes: "100vw",
alt: @item.name) %>
<% end %>