1

I'm using shrine to upload files from my rails application to S3. All is working fine, but I dont know how to display that file using redcarpet gem.

For example I can do this:

<div>
    <%= markdown("##title
    * ") %>
</div>

And works fine.

But if I do this:

<%= markdown(@rfile.rfile.url) %>

Is showing me a download link from S3.

How I can get the file content and not the file link?

4

1 回答 1

3

调用@rfile.rfile返回一个Shrine::UploadedFile对象,它有许多更方便的方法,而不仅仅是#url. 在这种方法上是#read,它检索文件的内容:

<%= markdown(@rfile.rfile.read) %>

但是,在这种情况下,文件将被打开和读取,但不会关闭。所以最好#open用块来调用,并调用#read产生的 IO 对象,可以整齐地写成

<%= markdown(@rfile.rfile.open(&:read)) %>
于 2017-07-06T01:17:21.520 回答