Jack Carter
Jack Carter

Reputation: 47

DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files`

My rails app, Rails 4.2.6, had been working perfectly but, after running the bundle exec rails server command as usual to start my web server for development I got this error message:

DEPRECATION WARNING: The configuration option `config.serve_static_assets`                              
has been renamed to `config.serve_static_files` to clarify its role (it  
merely enables serving everything in the `public` folder and is unrelated 
to the asset pipeline). The `serve_static_assets` alias will be removed in 
Rails 5.0. Please migrate your configuration files accordingly. (called 
from block in <top (required)> at /home/jack/Desktop/Rails/MegsBlog/config
/environments/development.rb:2)

I've tried changing method names in the config files as suggested in other communities and have restarted the server but still no luck, everything in my app works except there are no images which I'm sure is due to the method name changing

Upvotes: 3

Views: 3963

Answers (3)

Stefan
Stefan

Reputation: 603

We're upgrading our Rails app from Rails 3 to 4 at the moment (don't ask) and I've had the same issue.

Yes, config.serve_static_assets has been renamed to config.serve_static_files but that doesn't seem to be all.

config.serve_static_assets had always been set to false for our production app and assets like images were served by passenger/nginx.

I couldn't work out what was going on until I spotted heroku's Rails 4 docs which state

By default Rails 4 will not serve your assets. To enable this functionality you need to go into config/application.rb and add this line: config.serve_static_assets = true

So it appears that the value of config.serve_static_assets needs to be true or your images will not get served at all.

What I cannot currently figure out is why passenger/nginx will not handle these once that value is false. We do not want want Rails to handle serving these assets - the value was explicitly and specifically chosen to be false up to Rails 3.

Ultimately we will go the CDN route but this change is badly documented.

Upvotes: 0

H.B
H.B

Reputation: 115

This might be late, but I just encountered this issue having set config.serve_static_files = true.
The problem was that I needed to clear the assets pipeline and precompile,so I used this command locally:
rake assets:clean && rake assets:clobber && rake assets:precompile.
Note that you should keep the images and all styles and javascript in app/assets/ and not in public/.

I hope you have solved your problem already, or if not maybe this could help you and others, or you can share with us how you have solved it otherwise. Thanks!

Upvotes: 2

radoAngelov
radoAngelov

Reputation: 714

After updating the Rails version serve_static_assets method was changed to serve_static_files. Actually it is just a name change so you should not expect any changes of the behaviour of your app. Rename the config without changing its value and the warning will disappear.

Upvotes: 0

Related Questions