Ruby on Rails资产未在Heroku上进行预编译 [英] Ruby on Rails assets not being precompiled on Heroku

查看:61
本文介绍了Ruby on Rails资产未在Heroku上进行预编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以在本地开发环境中工作的项目,但是当它上传到Heroku时就中断了.在Heroku上访问我的项目时,我注意到从服务器收到404响应,说它找不到我的cssjs文件.我进行了一些搜索,发现Heroku没有预编译我的资产.在Heroku让我的项目进入睡眠状态之前,该项目将正常运行.在Heroku中唤醒项目后,cssjs会断开.

I have a project that works in the local development environment but breaks when it is uploaded to Heroku. When visiting my project on Heroku, I notice that I get 404 responses from the server saying that it could not find my css and js files. I have done some searching and found out that Heroku is not precompiling my assets. The project will work fine until Heroku puts my project to sleep. Upon waking the project in Heroku, the css and js are broken.

该项目使用的是Rails 4.2.4,我确保在我的Gemfile中的config/application.rbgem 'rails_12factor', group: :production中都包含了config.serve_static_assets = true.

The project is using Rails 4.2.4, I have made sure to to include config.serve_static_assets = true in my config/application.rb and gem 'rails_12factor', group: :production in my Gemfile.

cssjs仅在Heroku由于不活动而使项目进入睡眠状态时才会中断.有谁知道从睡眠中唤醒后Heroku如何自动预编译资产?

The css and js only breaks when Heroku puts the project to sleep due to inactivity. Does anyone know how to have Heroku automatically precompile assets when it is awaken from sleep?

推荐答案

Gemfile

gem 'rails_12factor', group: :production 

application.rb

默认情况下,Rails 4将不会为您的资产服务.要启用此功能,您需要进入config/application.rb并添加以下行:

application.rb

By default Rails 4 will not serve your assets. To enable this functionality you need to go into config/application.rb and add this line:

config.serve_static_assets = true

production.rb

config.serve_static_files = true
config.assets.compile = true

命令行

bundle install
bundle exec rake assets:precompile RAILS_ENV=production

确保图像位于/public文件夹中.

Make sure the images are in the /public folder.

参考此处

这篇关于Ruby on Rails资产未在Heroku上进行预编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆