Rails 3.1 改变了它处理 Assets 管道的方式,并且在部署到生产环境时会引起问题。
我正在使用 Apache 和Passenger,它们似乎工作正常。
我的作品是这样设置的(现在)。
# congif/environments/production.rb
config.cache_classes = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
我在 Ubuntu 上运行 rake assets:precompile 并启动服务器。没别的了。我的图片都没有加载。
传说中的“我在这个 URL 找不到图像”框。
我在 CentOS 上运行 rake assets:precompile 并启动服务器。还有……权限错误。
*Error Compiling CSS Asset*
Errno::EACCESS: Permission Denied - [app path]/tmp/cache/assets/E95
[path to RVM Ruby]/fileutils.rb:243:in 'mkdir'
我不能让它让步。任何帮助是极大的赞赏。谢谢!
更新
这个解决方案每次都对我有用:
首先清理你的 Assets
rm -rf public/assets
和
rake assets:clean RAILS_ENV=production
二、在#production.rb 中更改
config.assets.compile = false
到
config.assets.compile = true
第三,运行预编译你的 Assets
rake assets:precompile RAILS_ENV=production
四、在#production.rb 中更改
config.assets.compile = true
回到
config.assets.compile = false
第五,通过运行重新启动服务器:
touch tmp/restart.txt
第六,通过运行此命令取消对新创建 Assets 的权限限制
chmod -R 777 公共(public)/ Assets
第七,庆祝!!
最佳答案
这是一个简单的权限问题。授予服务器/守护进程以递归方式在 [app_path]/tmp 中创建文件的权限。
假设您的服务器进程使用 www-data
运行与您一起执行此操作的用户:
cd APP_PATH
chmod -R u+w tmp
如果目录不属于用户,则必须更改所有权:
chown -R www-data tmp
关于ruby-on-rails - Rails 3.1 部署到生产(使用 Apache 和Passenger) Assets 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7920298/