当我使用新的Rails 5.1方法’public_file_server.enabled’配置我的production.rb文件时,我无法预编译我的资产,然后部署我的应用程序(在Heroku上). 这是我在运行“RAILS_ENV =生产包exec rake assets:pre
这是我在运行“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.