问题
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?
回答1:
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
回答2:
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
回答3:
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.
来源:https://stackoverflow.com/questions/34380753/rails-application-assets-is-nil-on-heroku-after-upgrade-sprockets-rails-to-3-0-0