Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4.2.5 - Unable to upgrade "config.serve_static_files" to "config.public_file_server.enabled"

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).

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)>'

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)}"
  }

Here is my rails configuration in my gem file:

gem 'rails', '4.2.5'
gem 'railties', '4.2.5'

How can I access the newly merged method, 'public_file_server'?

like image 389
John Marbach Avatar asked Dec 07 '15 04:12

John Marbach


1 Answers

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.

like image 191
John Avatar answered Oct 12 '22 14:10

John