user4965201 user4965201 - 7 months ago 88
Ruby Question

Rails Capistrano precompile assets locally not loading on production

i deployed my rails app to the AWS server and tried running the rake assets:precompile locally and uploading on deploy .due to the out of memory issue on the server ,

this is my deploy.rb

# config valid only for current version of Capistrano
lock '3.5.0'

set :application, 'fullpower_tee'
set :repo_url, 'git_repo' # Edit this to match your repository
set :branch, :master
set :deploy_to, '/home/deploy/fullpower_tee'
set :pty, true
set :linked_files, %w{config/database.yml config/application.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}
set :keep_releases, 2
set :rvm_type, :user
set :rvm_ruby_version, 'ruby-2.2.1'

set :puma_rackup, -> { File.join(current_path, '') }
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock" #accept array for multi-bind
set :puma_conf, "#{shared_path}/puma.rb"
set :puma_access_log, "#{shared_path}/log/puma_error.log"
set :puma_error_log, "#{shared_path}/log/puma_access.log"
set :puma_role, :app
set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))
set :puma_threads, [0, 8]
set :puma_workers, 0
set :puma_worker_timeout, nil
set :puma_init_active_record, true
set :puma_preload_app, false

namespace :deploy do
namespace :assets do


desc 'Precompile assets locally and upload to servers'
task :precompile do
on roles(fetch(:assets_roles)) do
run_locally do
with rails_env: fetch(:rails_env) do
execute 'bin/rake assets:precompile'

within release_path do
with rails_env: fetch(:rails_env) do
old_manifest_path = "#{shared_path}/public/assets/manifest*"
execute :rm, old_manifest_path if test "[ -f #{old_manifest_path} ]"
upload!('./public/assets/', "#{shared_path}/public/", recursive: true)

run_locally { execute 'rm -rf public/assets' }


namespace :deploy do

after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end


and my config/environments/production.rb

# Compress JavaScripts and CSS
config.assets.compress = true

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false

# Generate digests for assets URLs
config.assets.digest = true

# config.assets.precompile += %w( *.css *.js )

# Add the fonts path
config.assets.paths << "#{Rails.root}/app/assets/fonts"

# Precompile additional assets
config.assets.precompile += %w( .svg .eot .woff .ttf )
config.assets.precompile += %w( *.js )
config.assets.precompile += [ 'admin.css',
'cupertino/jquery-ui-1.8.12.custom.css',# in vendor
'scaffold.css' # in vendor

and my application.rb has

config.assets.initialize_on_precompile = false

the capistrano deploy is successfully able to precompile assets locally and then uploading it to the shared/public directory , but i cannot see the assets loading on my website , been stuck in this issue since a day Please help !

this is my browser log
enter image description here



Given that your URLs are 404ing, and it doesnt show like the requests contain the hashes, you need to be sure to use stylesheet_link_tag in your layout/view files to load css files. As well as use the various asset helpers in the css itself for background images.

Capistrano deploys from git. You can configure it to pull from a local repo, if you dont want to push up shared assets to your github, but regardless the assets need to be in source control.

set :repo_url, 'file:///path/to/repo/.git'

To set it to a local repository.

If you absolutely dont want to store compiled changes in your git repo at all, you could run a scp command after the rake assets:precompile finishes.

execute 'scp -r public/assets/* user@serverip:/var/www/apps/yourapppath/shared/public/assets/*'

Have it point to the correct spot of course.

I'd also like to think your could optimize your assets a bit by having a few manifest files, rather than the 30 files you have in you precompile list.