I have an app that lets users download itineraries if they like the preview of the first page. In order to make the preview, I use PDF Reader to parse the original document and create a PDF version of the first page.
In development, the original itinerary is stored in the public folder.
@itin_preview = itinerary
reader = PDF::Reader.new("public/#{@itin_preview/document_file_name}")
formatted_page = reader.page(1)
formatted_text = formatted_page.text.gsub! /\s+/, ''
page_text = formatted_text.gsub!(/$/, "\n")
This return public/itinerary.pdf
. However, in production, the itinerary is stored on Amazon AWS, so i tried to configure an initializer with different paths in a YAML file for development and production, taken from here.
config.rb
APP_CONFIG = YAML.load_file("#{Rails.root}/config/initializers/config.yml")
config.yml
development:
itinerary_path: /public/#{@itin_preview.document_file_name}
production:
itinerary_path: <%= asset_path "#{@itin_preview.document_file_name}" %>
When I input the constant into my PDF Reader like so,
reader = PDF::Reader.new(APP_CONFIG[Rails.env]['itinerary_path'])
I get the following error:
Completed 500 Internal Server Error in 19ms (ActiveRecord: 1.3ms)
ArgumentError (input must be an IO-like object or a filename):
I have double checked that APP_CONFIG[Rails.env]['itinerary_path']
spits out public/itinerary.pdf
in development. So why does it work as a string but not as a Constant?
How can i get it to work?