【发布时间】:2020-11-20 01:54:53
【问题描述】:
我的网站有大量图表,这些图表每天都会在新数据可用时重新计算。这些图使用active_storage 存储在Amazon S3 上。一个典型的例子是
# app/models/graph.rb
class Graph < ApplicationRecord
has_one_attached :plot
end
在视图中
<%= image_tag graphs.latest.plot %>
graphs.latest 检索最新图的位置。每天都会创建一个新图表和附加图表,并删除旧图表/图表。
许多机器人,包括来自 Google 和 Yandex 的机器人正在为图表编制索引,但是当机器人返回并再次通过以下网址访问图像时会生成异常
www.myapp.com/rails/active_storage/representations/somelonghash
有没有办法为图表生成一个持久链接,当图表/图表被删除然后重新计算时不会过期。如果做不到这一点,有没有办法阻止机器人访问这些地块。
请注意,我目前在 routes.rb 文件的末尾有一个总称:
get '*all', to: 'application#route_not_found', constraints: lambda { |req|
req.path.exclude? 'rails/active_storage'
} if Rails.env.production?
在总括中排除活动存储是对此issue 的回应。删除 active_storage 豁免是很诱人的,但这可能会停止正确的 active_storage 路由。
也许我可以在rack_rewrite.rb 中添加一些东西来解决这个问题?
【问题讨论】:
标签: ruby-on-rails amazon-s3 robots.txt rails-activestorage