Rails : Upload secret files using Capistrano before booting

This answer is tested with Capistrano 3.6.1

Well, in that case, you would have to make capistrano upload your application.yml(database.yml if its ignored from git).

# in config/deploy.rb

# Default value for :linked_files is []
append :linked_files, 'config/database.yml', 'config/application.yml'

Now write some code to upload the files to the server

namespace :upload do
  desc 'Upload shared files to the server'
  task :yml_files do
    on roles(:web) do |host|
      fetch(:linked_files).each do |common_file|
        upload! common_file, "#{fetch(:deploy_to)}/shared/#{common_file}"
      end
    end
  end
end

Now you need to trigger the above mentioned capistrano task just before a very specific event.

# config/deploy.rb

before 'deploy:check:linked_files', 'upload:yml_files'

This will make sure the necessary environment variables are set before your deployed tries to boot your application in the production server.