如何将Rails 4.2.5的config.serve_static_files配置升级为config.public_folder?
- 内容介绍
- 文章标签
- 相关推荐
本文共计399个文字,预计阅读时间需要2分钟。
在使用Rails 5.1时,尝试在`production.rb`中设置`public_file_server.enabled`配置,却无法预编译资产。部署到Heroku后遇到的问题可能是:
1. `public_file_server.enabled`配置导致预编译资产时出错。
2.可能是Heroku环境下的配置问题。
解决方案如下:
ruby
在production.rb中注释掉或删除public_file_server的相关配置config.public_file_server.enabled=false然后尝试重新预编译资产:
shellRAILS_ENV=production bundle exec rake assets:precompile
确保在Heroku环境中运行此命令:
shellheroku run rake assets:precompile
这应该能解决预编译资产的问题。如果问题依旧,检查Heroku的日志以获取更多错误信息。
当我使用新的Rails 5.1方法’public_file_server.enabled’配置我的production.rb文件时,我无法预编译我的资产,然后部署我的应用程序(在Heroku上).这是我在运行“RAILS_ENV =生产包exec rake assets:precompile”后看到的错误:
rake aborted! NoMethodError: undefined method `public_file_server' for #<Rails::Application::Configuration:0x007f81f0624b60> /Users/jmarbach/Documents/rubyscripts/concorde/config/environments/production.rb:21:in `block in <top (required)>' /Users/jmarbach/Documents/rubyscripts/concorde/config/environments/production.rb:1:in `<top (required)>' /Users/jmarbach/Documents/rubyscripts/concorde/config/environment.rb:5:in `<top (required)>'
以下是我的production.rb文件中的相关行:
# Leverage browser caching config.static_cache_control = 'public, max-age=1000' # Set header expiray date config.public_file_server.enabled = true config.public_file_server.headers = { 'Cache-Control' => 'public, s-maxage=31536000, maxage=15552000', 'Expires' => "#{1.year.from_now.to_formatted_s(:rfc822)}" }
这是我的gem文件中的rails配置:
gem 'rails', '4.2.5' gem 'railties', '4.2.5'
如何访问新合并的方法’public_file_server’?
正如您在问题中指出的那样,“public_file_server”是Rails 5.0的一项功能.正如您的gemfile所示,您正在运行rails 4.2.5.您需要升级到Rails 5.0.本文共计399个文字,预计阅读时间需要2分钟。
在使用Rails 5.1时,尝试在`production.rb`中设置`public_file_server.enabled`配置,却无法预编译资产。部署到Heroku后遇到的问题可能是:
1. `public_file_server.enabled`配置导致预编译资产时出错。
2.可能是Heroku环境下的配置问题。
解决方案如下:
ruby
在production.rb中注释掉或删除public_file_server的相关配置config.public_file_server.enabled=false然后尝试重新预编译资产:
shellRAILS_ENV=production bundle exec rake assets:precompile
确保在Heroku环境中运行此命令:
shellheroku run rake assets:precompile
这应该能解决预编译资产的问题。如果问题依旧,检查Heroku的日志以获取更多错误信息。
当我使用新的Rails 5.1方法’public_file_server.enabled’配置我的production.rb文件时,我无法预编译我的资产,然后部署我的应用程序(在Heroku上).这是我在运行“RAILS_ENV =生产包exec rake assets:precompile”后看到的错误:
rake aborted! NoMethodError: undefined method `public_file_server' for #<Rails::Application::Configuration:0x007f81f0624b60> /Users/jmarbach/Documents/rubyscripts/concorde/config/environments/production.rb:21:in `block in <top (required)>' /Users/jmarbach/Documents/rubyscripts/concorde/config/environments/production.rb:1:in `<top (required)>' /Users/jmarbach/Documents/rubyscripts/concorde/config/environment.rb:5:in `<top (required)>'
以下是我的production.rb文件中的相关行:
# Leverage browser caching config.static_cache_control = 'public, max-age=1000' # Set header expiray date config.public_file_server.enabled = true config.public_file_server.headers = { 'Cache-Control' => 'public, s-maxage=31536000, maxage=15552000', 'Expires' => "#{1.year.from_now.to_formatted_s(:rfc822)}" }
这是我的gem文件中的rails配置:
gem 'rails', '4.2.5' gem 'railties', '4.2.5'
如何访问新合并的方法’public_file_server’?
正如您在问题中指出的那样,“public_file_server”是Rails 5.0的一项功能.正如您的gemfile所示,您正在运行rails 4.2.5.您需要升级到Rails 5.0.
