John Marbach
John Marbach

Reputation: 143

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

Upvotes: 5

Views: 5544

Answers (2)

Oleksii Danylevskyi
Oleksii Danylevskyi

Reputation: 35

I have tried everything that belongs to Ruby on Rails but decided to jump over to nginx configurations. Here is what helps me to leverage browser caching:

location ~* \.(?:jpg|jpeg|gif|png|ico|gz|js|css|ttf)$ {
    expires 1M;
    access_log off;
    add_header Cache-Control "public";
}

Hope it helps anybody:)

Upvotes: 0

John
John

Reputation: 10079

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.

Upvotes: 8

Related Questions