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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.