Rails 3.1 - 如何判断资产是否在生产环境中进行预编译?
试图掌握部署 Rails 3.1 应用程序的窍门...
根据我所读到的内容,我已将以下代码放入我的deploy.rb中:
before "deploy:symlink", "assets:precompile"
namespace :assets do
desc "Compile assets"
task :precompile, :roles => :app do
run "cd #{release_path} && rake RAILS_ENV=#{rails_env} assets:precompile"
end
end
但说实话,我看不出与或没有它。我在这里缺少什么吗?
编辑*找到了答案:
要预编译生产资源,您通常会执行以下 rake 任务(在生产服务器上)。
$bundle exec rake 资产:预编译 这会将所有资产写入 public/assets 目录,同时在文件名中包含 MD5 指纹以增加缓存优势。
注意:在生产中,使用 image_tag、asset_path、javascript_include_tag 等对视图中资产的所有引用都会自动在文件名中包含此指纹,以便提供正确的版本。
Trying to get the hang of deploying a rails 3.1 App ...
Based on what I've read, I've put the following code in my deploy.rb:
before "deploy:symlink", "assets:precompile"
namespace :assets do
desc "Compile assets"
task :precompile, :roles => :app do
run "cd #{release_path} && rake RAILS_ENV=#{rails_env} assets:precompile"
end
end
But to tell you the truth, I can't notice any difference with or without it. Is there something I'm missing here?
EDIT* found the answer:
To pre-compile assets for production you would normally execute the following rake task (on the production server).
$ bundle exec rake assets:precompile
This would write all the assets to the public/assets directory while including an MD5 fingerprint in the filename for added caching benefits.NOTE: In production all references to assets from views using image_tag, asset_path, javascript_include_tag, etc. will automatically include this fingerprint in the file name so the correct version will be served.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
需要进行配置,但默认情况下应该正确设置。进入您的 config/application.rb 并查看是否找到以下内容:
您的 production.rb 文件中也应该有这些内容:
应该这样设置。是吗?
There is configuration to do, but it should be correctly set by default. Get in your config/application.rb and see if you find this:
You should also have those in your production.rb file:
This should be set that way. Is it?