Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing pdfs in Rails app

How would I store a pdf in my Rails app so that users can access/download them?

In my migration, would i i use the datatype t.binary?

Then in my controller/view, how should I present this data?

like image 305
alamodey Avatar asked Sep 06 '25 03:09

alamodey


1 Answers

The answer here is probably it depends. Depends on the size and number of PDFs, where users have to be logged in to view them etc.

If you have lots of large PDFs, its probably not a good idea to store them in the database - just store them on the filesystem and store a file location in the database model.

If you do want to store them in the database, then using a binary column is the way to go.

If users don't have to be logged in to download the PDF's, then you could just place them into the public folder (inside a subfolder) and generate links to them for download - then your controller would only need to generate a link to a static PDF file, and the front end webserver will serve them up automatically without using a Rails process.

like image 179
Stephen ODonnell Avatar answered Sep 07 '25 20:09

Stephen ODonnell