我尝试在模型的 show
View 上显示存储在 Amazon S3 上的附加 pdf,但我无法让它工作。
到目前为止,我最好的尝试是在 s3 上获取上传文件的 url,如下所示:
#controller.rb
@key = upload.file.service_url
成功获取文件的URL,并在 View 中用iframe显示。遗憾的是这不起作用。
#view.html.erb
<iframe src=" <% @key %> " width="100%" height="500px">
它产生这个:
我的上传
模型:
class Upload < ApplicationRecord
belongs_to :user
has_one_attached :file
end
非常感谢
最佳答案
你的view.html.erb应该是这样的
#view.html.erb
<iframe src=<%= @key %> width="100%" height="500px"></iframe>
这个(“<% @key %> ”)基本上是 Rails 的字符串
关于ruby-on-rails - 使用 Rails 显示存储在 Amazon S3 上的 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60776998/