Day 2
Got the PDFKit gem to work! I’m working on Wylie’s app to be able to search and select multiple drugs, output a table of the results and their side effects, and export the table to a PDF.
I got a (keyword “a”) table to export to PDF, but I’ll need to ensure it contains only the drugs that were selected in the index page. I believe I’ll need to create a Search model, with a joint table containing the drugs for each search (each entry will have a drug_id / drug_name and a search_id). I also want to incorporate an Excel import feature, so admins can update the drug and side effect database as they please — I think I’ll have to play around with some combination of the Roo and Paperclip gems.
Now to reflect on the challenges I faced today —
I originally wanted to use the WickedPDF gem, but had difficulty getting it to work (following documentation / lack of documentation). I then tried Prawn, which has a pretty great RailsCasts video to walk you through. Then I realized you can’t render HTML views to PDFs using Prawn. You can render texts / tables … though I couldn’t really get this to work in the latest version of Rails. Ultimately, I was able to PDFKit to work using this very helpful tutorial!
So that was pretty freaking exciting, getting it to work on my local server. HOWEVER, getting this on Heroku was quite a pain in my arse, as has been the case with many of my apps. To figure this out, I used a combination of the following links (in sequence):
- Using PDFKit with Heroku
- Using multiple buildpacks in Heroku
“Buildpacks are scripts that are run when your app is deployed. They are used to install dependencies for your app and configure your environment.” - Ensuring buildpacks are added in order
- Setting config.assets.compile to true
Still don’t fully understand what this does, though I’ve had to perform this action before to ensure my images showed in Heroku
And that was it! Tada. Success. Bliss. etc etc.
Goodnight.
