Adding precompiled assets to .rb vs application.rb

Today, I added an extra css file to my app that doesn’t load with the main application.css. I added it to config/environments/production.rb so it would compile in production:

config.assets.precompile += %w( public.css )

I ran rake assets:precompile but it did not compile the file. Eventually I figured out that if I add that same line to config/application.rb instead, it does compile. Is this expected? I thought it was supposed to go in production.

Did you run the task locally? If so Rails assumed your env was development (which doesn’t have that configuration). It worked when you added to application.rb because its configuration get applied to all environment specific configurations.

Try running the rake task with RAILS_ENV=production - it would be rake assets:precompile RAILS_ENV=production

Thanks @patkoperwas that was the problem. I guess it was a long day.