Rails4 and Assets
I spent a ridiculous amount of time trying to get a background image to show on a production server running a new rails4 app. Everything looked fine on my laptop, but once I deployed to the server, the image wouldn’t show. I only had one image on the site, but I’m pretty sure that if I had more, none of them would have showed.
The image was here, just a background image in css.
body { font-family: ProximaNova-Regular; background-image:image-url('grayscale-sm.png'); background-repeat:no-repeat; background-attachment:fixed; background-position:center top; padding-left: 25px; padding-right: 25px; font-size: 12pt; }
I tried changing the image-url to all sorts of different things and it didn’t matter. What fixed it was in my deployment script.
Here’s what didn’t work.
desc 'assets_precompile' task :assets_precompile, roles: :app do run "cd #{release_path}; rake assets:precompile" end
And here’s how to fix it.
desc 'assets_precompile' task :assets_precompile, roles: :app do run "cd #{release_path}; rake assets:precompile RAILS_ENV=production" end
I don’t really understand why this is necessary, since I’m running the command on the production server, but it is. Possibly this is a bug that will get fixed later. But for now, I need to remember to add the environment. Thus, this post.