我可以在我的Rails 4.1项目中编译我的资产,如下所示:
$ RAILS_ENV=staging bin/rake assets:precompile
I, [2015-03-26T17:23:21.632726 #26321] INFO -- : Writing /MyProject/public/assets/active_admin-a46314b7dc1a06e662695c2093e33d96.js
I, [2015-03-26T17:23:21.748271 #26321] INFO -- : Writing /MyProject/public/assets/application-adc2c7c08b35fae05d8bfc73d1696dea.js
I, [2015-03-26T17:23:21.833131 #26321] INFO -- : Writing /MyProject/public/assets/active_admin-36d00173ec2474695cd54a330636bac9.css
I, [2015-03-26T17:23:21.851637 #26321] INFO -- : Writing /MyProject/public/assets/application-0930e157132302bc8b8666143a832af2.css
I, [2015-03-26T17:23:21.861676 #26321] INFO -- : Writing /MyProject/public/assets/debug-aeffd81aa2ee2b35a0d779b9335c9749.css
同样在服务器上直接我可以使用rake创建资产:
user@server$ RAILS_ENV=staging bundle exec rake assets:precompile
I, [2015-03-26T17:40:11.761707 #30743] INFO -- : Writing /var/www/my_project/releases/20150326161842/public/assets/active_admin-a46314b7dc1a06e662695c2093e33d96.js
I, [2015-03-26T17:40:11.806881 #30743] INFO -- : Writing /var/www/my_project/releases/20150326161842/public/assets/application-adc2c7c08b35fae05d8bfc73d1696dea.js
I, [2015-03-26T17:40:11.847215 #30743] INFO -- : Writing /var/www/my_project/releases/20150326161842/public/assets/active_admin-36d00173ec2474695cd54a330636bac9.css
但是,当我想在远程服务器上执行相同操作时,则不会创建任何资产。
当我通过capistrano运行命令时,这是:debug
输出:
$ cap staging deploy:assets:precompile -t
** Invoke staging (first_time)
** Execute staging
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke rbenv:validate (first_time)
** Execute rbenv:validate
DEBUG [92cdd4bf] Running /usr/bin/env [ -d ~/.rbenv/versions/2.1.2 ] as user@server.com
DEBUG [92cdd4bf] Command: [ -d ~/.rbenv/versions/2.1.2 ]
DEBUG [92cdd4bf] Finished in 0.421 seconds with exit status 0 (successful).
** Invoke rbenv:map_bins (first_time)
** Execute rbenv:map_bins
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke deploy:set_rails_env (first_time)
** Execute deploy:set_rails_env
** Invoke deploy:set_rails_env
** Invoke deploy:assets:precompile (first_time)
** Execute deploy:assets:precompile
我的Capfile
包含require 'capistrano/rails/assets'
到require 'capistrano/rails'
。
我的staging.rb
包含以下指令:
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
config.assets.digest = true
为什么Capistrano不会生成资产?
答案 0 :(得分:11)
来自here:
set :assets_roles, [:web, :app] # Defaults to [:web]
我认为您的服务器没有web
角色(或者您指定app
角色)。因此,请尝试如上所述指定assets_roles
变量或更改服务器的角色。