Disambiguation: There are two popular plugins called "parallax.js". I'm referring to this one.
In development, parallaxed and non-parallaxed images work perfectly in my ERB template. But in production (on Heroku), only the non-parallaxed images are rendering. I currently suspect my problem is with the Rails asset pipeline, but the recommended fixes haven't worked (see below).
The parallax.js
docs suggest the following usage:
<div class="parallax-window" data-parallax="scroll" data-image-src="/path/to/image.jpg"></div>
But in order to use the asset pipeline, I've changed it to:
<div class="parallax-window" data-parallax="scroll" data-image-src="<%= image_url('image_file.jpeg') %>"></div>
(In addition to image_url
, I've also tried image_tag
and image_path
.)
As mentioned, this all works just fine on my local machine.
But in production, the Chrome browser console logs errors for the missing images:
Failed to load resource: the server responded with a status of 404 (Not Found)
So I went down the rabbit hole:
Other SO pages (ie: here and here) suggest doing variations of rake assets:precompile RAILS_ENV=production
or heroku run rake assets:precompile
.
The latter command spends several minutes compiling unrelated css & js assets, and does not resolve the problem. The former command yields the following error:
Devise.secret_key was not set. Please add the following to your Devise initializer:
config.secret_key = (... and so on)
Using the heroku console I ensured proper values ARE present for ENV['SECRET_KEY']
and ENV['SECRET_KEY_BASE']
.
In my devise.rb
, I have:
config.secret_key = ENV['SECRET_KEY_BASE'] if Rails.env == 'production'
In production.rb
I have:
config.serve_static_assets = true
config.assets.compile = true
config.assets.digest = true
This might be more info than necessary but I've included this since it all seems related.
Thank you.