Reputation: 507
I check this command Rails.application.assets
in local console it work but in heroku console it return Nil
.
but when I rollback to use sprockets-rails 2.3.3 and check Rails.application.assets
in heroku console it return value.
what happened?
Upvotes: 0
Views: 980
Reputation: 1436
I solved this by adding an application helper like this:
def image_exists?(path)
if Rails.env == "development" && Rails.application.assets.find_asset(path)
return true
elsif Rails.env == "production" && Rails.application.assets_manifest.assets[path]
return true
else
return false
end
end
Then I could check if an image exists by finding the path and running
image_exists?(path)
In my app, usually the path is just the image file name, unless the image is in a subfolder within the images directory.
Upvotes: 0
Reputation: 1246
This was the result of a change in sprockets-rails 3. See the issue https://github.com/rails/sprockets-rails/issues/237
You can get around the issue for now by setting config.assets.compile = true
in /config/environments/production.rb
Upvotes: 3
Reputation: 2420
You might need to change some of your code to be compatible with sprockets-rails 3, please read https://github.com/rails/sprockets/blob/master/UPGRADING.md
Upvotes: 0