Search code examples
ruby-on-railspdfamazon-ec2publicrails-5.1.6

Static PDF file on rails app not showing on website upon deploying


I've added this line <p><%= link_to 'Download My Resume', "resume.pdf", { :class=>"btn btn-default btn-lg" } %></p> to my html.erb, the link works perfectly on my local server but when I deploy it to my aws server, the webpage cannot be opened.

error message in logs:

ActionController::RoutingError (No route matches [GET] "/resume.pdf"):

I'm using Rails 5.1.6. I've already set config.public_file_server.enabled = true I'm pretty perplexed on what's going on, would appreciate some help. I do not want to use any pdf gem.

Thanks!


Solution

  • if you have just puma as the server, be sure that you set

    config.public_file_server.enabled = true
    

    in your production.rb file.

    But I recommend to use nginx to serve this type of files.

    I made a simple test starting a server in production mode and the error I have when trying to go to a public file is that the secret_key_base isn't set for production environment. I added a value for that on environments/production.rb and it worked

    config.secret_key_base = ENV["SECRET_KEY_BASE"]
    

    and of course, SECRET_KEY_BASE needs to have a value.