当我使用新的Rails 5.1方法配置我的production.rb文件' public_file_server.enabled'时,我无法预编译我的资产,然后部署我的应用程序(在Heroku上)。
这是我在运行" RAILS_ENV =生产包exec rake资产后看到的错误:预编译":
SELECT DISTINCT B1.BRANCHSTATE
FROM BRANCH b1
WHERE NOT EXISTS
(SELECT 'X'
FROM branch b2,
orders o,
customer c,
employee e
WHERE o.salesperson = e.employeeid AND
b2.branchnumber = e.empbranch AND
c.customerid = o.customerid AND
b1.branchstate = c.custstate)
以下是我的production.rb文件中的相关行:
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)>'
这是我的gem文件中的rails配置:
# 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)}"
}
如何访问新合并的方法&#39; public_file_server&#39;?
答案 0 :(得分:7)
正如您在问题中指出的那样,“public_file_server”是Rails 5.0的一项功能。正如您的gemfile所示,您正在运行rails 4.2.5。您需要升级到Rails 5.0。
答案 1 :(得分:0)
我已经尝试了所有属于Ruby on Rails的东西,但决定跳转到nginx配置。这有助于我利用浏览器缓存:
location ~* \.(?:jpg|jpeg|gif|png|ico|gz|js|css|ttf)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
希望它可以帮助任何人:)