我的应用程序的公共(public)(public/assets)目录中没有任何 Assets 文件夹。当我尝试使用 capistrano v3 进行部署时。在我的远程计算机中创建了一个名为 public/assets 的新文件夹。我还收到以下错误,因为它在 public/assets(public/assets/manifest*) 下搜索名为 manifest.yml 的文件。有必要吗??这样做的目的是什么???
//getting the following error while deploying
DEBUG [014a40e4] Running /usr/bin/env [ -L /home/ec2-user/capistrano-3/my_app/releases/20140117124107/public/assets ] on 50.13.220.55
DEBUG [014a40e4] Command: [ -L /home/ec2-user/capistrano-3/my_app/releases/20140117124107/public/assets ]
DEBUG [014a40e4] Finished in 0.602 seconds with exit status 1 (failed).
DEBUG [9c5901ab] Running /usr/bin/env [ -d /home/ec2-user/capistrano-3/my_app/releases/20140117124107/public/assets ] on 50.13.220.55
DEBUG [9c5901ab] Command: [ -d /home/ec2-user/capistrano-3/my_app/releases/20140117124107/public/assets ]
DEBUG [9c5901ab] Finished in 0.639 seconds with exit status 1 (failed).
////此错误位于跟踪末尾
** 调用部署: Assets :backup_manifest(first_time)
** 执行deploy:assets:backup_manifest
DEBUG [a08f4c02] cp:
DEBUG [a08f4c02] cannot stat `/home/ec2-user/capistrano-3/my_app/releases/20140117064709/public/assets/manifest*'
DEBUG [a08f4c02] : No such file or directory
DEBUG [a08f4c02]
cap aborted!
cp stdout: Nothing written
cp stderr: Nothing written
Tasks: TOP => deploy:assets:backup_manifest
The deploy has failed with an error: #<SSHKit::Command::Failed: cp stdout: Nothing written
cp stderr: Nothing written
>
** Invoke deploy:failed (first_time)
** Execute deploy:failed
最佳答案
从外观上看,您可能在应用程序中使用 3.1 或更高版本的 Rails。
基本上,来自指南:
The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB.
以下是您需要了解的所有信息:http://guides.rubyonrails.org/asset_pipeline.html
如指南中所述,您可以通过在 config/application.rb 文件中放置/修改以下代码来禁用它:
config.assets.enabled = false
如果您继续使用 Assets 管道,则可以使用以下命令预编译 Assets :
rake assets:precompile
# or
rake assets:precompile:all
关于 menifest.yml(来自指南本身):
rake 任务还会生成一个 manifest.yml,其中包含包含所有 Assets 及其各自指纹的列表。 Rails 辅助方法使用它来避免将映射请求返回给 Sprockets。典型的 list 文件如下所示:
---
rails.png: rails-bd9ad5a560b5a3a7be0808c5cd76a798.png
jquery-ui.min.js: jquery-ui-7e33882a28fc84ad0e0e47e46cbf901c.min.js
jquery.min.js: jquery-8a50feed8d29566738ad005e19fe1c2d.min.js
application.js: application-3fdab497b8fb70d20cfc5495239dfc29.js
application.css: application-8af74128f904600e41a6e39241464e03.css
所以,当你运行 rake 任务时。它将生成 menifest.yml 文件,其中包含您的 Assets 条目,包括 md5 哈希摘要,用于在客户端级别缓存您的 Assets 。每次运行 rake 任务时,您都会获得 Assets 的新哈希值。当浏览器收到服务器的响应时,它会验证/无效您的 Assets 。
我鼓励您使用 Assets 管道,因为它还将使您能够以更好/更简单的方式使用 CDN。不过,归根结底,这是您的选择。
更新:
为了在 capistrano 3 中部署(因为 capistrano 3 有很多 DSL 更改),需要在 Capfile 中添加:require 'capistrano/deploy'
。因此,您不必为部署编写自己的 precompile_assets 任务。
看看这个答案:https://stackoverflow.com/a/15690628/645886 ,这个:http://blog.blenderbox.com/2013/11/06/precompiling-assets-with-capistrano-3-0-1/ 。我希望这有帮助。
关于ruby-on-rails - 使用 capistrano 3 部署时,会在 public 内部自动创建 asset 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21226880/