Rails 4.2.5-无法升级“ config.serve_static_files”到“ config.public_file_server.enabled”; [英] Rails 4.2.5 - Unable to upgrade "config.serve_static_files" to "config.public_file_server.enabled"

查看:84
本文介绍了Rails 4.2.5-无法升级“ config.serve_static_files”到“ config.public_file_server.enabled”;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用新的Rails 5.1方法 public_file_server.enabled配置production.rb文件时,无法预编译资产,然后(在Heroku上)部署应用程序。

When I configure my production.rb file with the new Rails 5.1 method, 'public_file_server.enabled', I am unable to precompile my assets and then deploy my application (on Heroku).

这是我在运行 RAILS_ENV =生产捆绑程序执行耙资产:预编译后看到的错误:

Here's the error I see after running "RAILS_ENV=production bundle 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文件中的相关行:

Here are the relevant lines in my production.rb file:

# 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配置:

Here is my rails configuration in my gem file:

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。

As you indicate in your question, "public_file_server" is a Rails 5.0 feature. As indicated by your gemfile, you're running rails 4.2.5. You need to upgrade to Rails 5.0.

这篇关于Rails 4.2.5-无法升级“ config.serve_static_files”到“ config.public_file_server.enabled”;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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