Heroku not showing my assets - ruby-on-rails

I've precompiled my assets on my local machine, yet when I pushed it to heroku, all my assets are no longer available, they don't seem to have compiled.
I recently had to reinstall rails/ruby/rvm and this is when the error started occurring.
Let me know if I can give you any more information.

In /config/environments/production. set:
config.cache_classes = true
config.serve_static_assets = true
config.assets.compile = true
config.assets.digest = true

Related

Rails 4.2: image path and fingerprint only added when config.assets.compile = true

In production, the correct paths to my images are not called with the image tag, and the md5 fingerprint is not added. The image names (e.g. "pretty_picture.jpg") are stored in the database. The precompilation files are all present in the public folder including the manifest file.
When called with image_tag:
image_tag #test_question.question.image
I get:
<img src="/images/pretty_picture.jpg">
If I set config.assets.compile = true in production.rb the image is rendered and I get:
<img src="/assets/images/pics/pretty/pretty_picture-e0df5012b6930cda4efaa866af22a63f.jpg" >
My hack solution is to use (in HAML)
%img{src: "/assets/"+Rails.application.assets.find_asset(#test_question.question.image).digest_path}
In production.rb I have
config.assets.digest = true
config.assets.enabled = true
config.serve_static_files = false
config.assets.compile = false
Setting the config.assets.compile to true in production is not recommended. This seems like very strange behaviour on behalf of sprockets and the asset pipeline. Any idea what is wrong with the use of image_tag here?
In production, you should precompile the assets before starting the server, with the following command (and automate it to do it every time you deploy):
rake assets:precompile RAILS_ENV="production"
and keep config.assets.compile = false in your production.rb. Check in the Asset Pipeline Guide.

Static assets aren't up to date in production

I have a static asset being served at /assets/images/example.svg. I made a change to this SVG in the codebase, and pushed to production.
It's not updated because I have static asset caching set up:
config.serve_static_assets = true
config.cache_store = :redis_store, "#{ENV['OPENREDIS_URL']}/0", { expires_in: 90.minutes }
And here's the response headers for the asset:
I've run this command, which still doesn't expire my static assets:
heroku run rake tmp:cache:clear assets:clean:all assets:precompile
I've tried incrementing the config.assets.version, which didn't work either:
config.assets.version = '1.1'
How do you deal with static assets changing in the codebase? How do I manually expire my redis cache for a specific asset, or in general?
I'd just wait another 30 minutes for it to expire. From what I understand, when you serve static assets on heroku you lose out on fingerprinting, meaning the cache would not be invalidated even if you change your assets version.
I recently went the way of putting everything on S3 using the asset_sync gem. Everything has been incredibly peachy ever since.
Here's the configuration if you choose to go that route:
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Enable assets
config.assets.enabled = true
# Generate digests for assets URLs
config.assets.digest = true
config.action_controller.asset_host = "//your-bucket.s3.amazonaws.com"
In /config/environments/production.rb , try setting:
config.cache_classes = true
config.serve_static_assets = true
config.assets.compile = true
config.assets.digest = true

How to host assets locally under different hostname?

I would like to test my assets from multiple hostnames ex: http://assets1.somehost.dev, http://assets2.somehost.dev
My assets configs from development.rb
config.serve_static_assets = false
config.assets.compile = true
config.assets.digest = true
config.action_controller.asset_host = "http://assets%d.somehost.com"
config.assets.compress = false
config.assets.debug = false
So I would like to setup config.action_controller.asset_host = "http://assets%d.somehost.dev"
To test that locally.
Add the following line to your hosts file (I think rails only uses four assets hosts by default):
127.0.0.1 http://assets1.somehost.dev http://assets2.somehost.dev http://assets3.somehost.dev http://assets4.somehost.dev
Wikipedia has a list of where to find your hosts file based on your platform.

rails no route matches after assets:precompile

I am running Rails 3.2.8 application in production mode.
I have routing problems after i have done "rake assets:precompile".
My log message is :
ActionController::RoutingError (No route matches [GET] "/corp/assets/application-cf24b2a92e88a02835248f85a9f3c462.css"):
This file exists and it is in current location.
My routes are under scope "corp".
My config "config/application.rb" have option "config.assets.enabled = true".
My config "config/environments/production.rb" have following options:
config.serve_static_assets = true
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
Application works fine in development mode.
Before that assets:precompile everything was fine.
After few hours of searching of posts i can't find any solution to my problem.
Please help me fix this!
In production mode, Rails will not be responsible for serving static assets. Therefore, you are getting this error. This is controlled by this setting in config/environment/production.rb in your application:
config.serve_static_assets = false
You can either set to that true or use a real server like Apache or Nginx which will serve the static assets. I suspect Pow may also do it.
Update
try this
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
# Generate digests for assets URLs
config.assets.digest = false

Rails 3.1 Production - Javascript is missing .js endings on deployment

I've just made my Rails app and deployed it to Heroku. A very weird thing happened in the process though. Half of my javascript-files are missing their endings (.js). I have absolutely no idea why this is.I've searched far and wide, but I don't seem to find an answer.
My production-config looks like this:
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
# Generate digests for assets URLs
config.assets.digest = true
config.assets.precompile << '*.js'
Any suggestions?
Posted this other similar question 1 hour ago (http://stackoverflow.com/questions/9049023/rails-3-1-production-javascript-loads-but-doesnt-execute). Sorry for the spamming.
Does this help? You didn't show where your js files are included. If they have dots in the name, apparently you need to tell Rails.
asset:precompile for .js files? rails 3.1

Resources