1

I'm using Paperclip to upload a .js file.

My model (Bypassing validation just for Testing Purposes):

# Script Asset
has_attached_file :asset
do_not_validate_attachment_file_type :asset

The upload itself works as it should, but how to open the uploaded file so i can display it in the View?

I tried and searched a lot, but i can't find a working solution. Just passing <%= @test.asset %> brings back the path of the Document.

Do i have to write a method for passing the Document to a text ?

Mini John
  • 7,855
  • 9
  • 59
  • 108
  • unless i missed your question <%= javascript_include_tag @test.asset %> – Abs May 27 '14 at 07:08
  • No No, you missed it :) Think of it like a Text file uploaded by a user.. I want to show the content of that Text File. – Mini John May 27 '14 at 07:10
  • 1
    ah..see if this helps Paperclip.io_adapters.for(@test.asset).read doesn't require writing to (and removing from) the local file system. http://stackoverflow.com/questions/6555468/how-do-you-access-the-content-of-a-text-file-uploaded-with-paperclip-ruby-on-r – Abs May 27 '14 at 07:16
  • 1
    Oh, i literally searched 100 SO Questions and didn't found that! You mind answering so i can upvote ? – Mini John May 27 '14 at 07:17
  • In that case..Did the needful :) – Abs May 27 '14 at 07:21

1 Answers1

1
 Paperclip.io_adapters.for(@test.asset).read 

Doesn't require writing to (and removing from) the local file system.

Abs
  • 3,902
  • 1
  • 31
  • 30