robo-monk
robo-monk

Reputation: 131

Display PDF stored on Amazon S3 with Rails

Im trying to display an attached pdf which is stored on Amazon S3 on the model's show view, but I can't get it to work. So far my best attempt was to get the uploaded file's url on s3 like this :

#controller.rb

@key = upload.file.service_url

which successfully gets the URL of the file, and display it with iframe in the view. Which sadly doesn't work.

#view.html.erb

<iframe src=" <% @key %> " width="100%" height="500px">

It produces this:

iframe

My Upload model:

class Upload < ApplicationRecord
  belongs_to :user
  has_one_attached :file
end

Thanks a lots

Upvotes: 2

Views: 738

Answers (1)

Semih Arslanoglu
Semih Arslanoglu

Reputation: 1129

Your view.html.erb should be like this

#view.html.erb

<iframe src=<%= @key %> width="100%" height="500px"></iframe>

This (" <% @key %> ") is a string for rails basically

Upvotes: 2

Related Questions