Assets not rendering in production rails - ruby-on-rails

I have precompiled the assets in production but the application is not able to load the assets. My app is deployed on AWS EC2
I checked in the server in public/assets folder the application.css is present.
but still it says 404 error.
My production.rb configuration is
My nginx.conf settings are:

The 404 is based on that line in your config: config.serve_static_files = true. That might be the wrong name depending on your rails version. I believe that setting is named config.serve_static_assets in Rails prior to version 5.
If you don't have a server (nginx/etc) then you want that setting to be true. Otherwise you need to reconfigure your server to point at your /public directory, and make sure rake assets:precompile runs successfully.

I had the same problem
set config.assets.compile = True
It works for me.

The problem was my configuration in nginx of root path was wrong. so assets were not pointing to wrong path.
I changed in nginx.conf:
from root /home/deploy/appname/public
to root /home/deploy/appname/current/public
AND in production.rb
config.serve_static_assets = true to config.serve_static_assets = false

I did the same as you:
root /home/deploy/appname/public root => /home/deploy/appname/current/public
And that works for me. With the unique difference that i left the config/production.rb file like this:
config.public_file_server.enabled = true
config.assets.compile = true
I'm using Rails 5.

Related

rails environment production not working no files loaded

in my Rails application all my js and css is in public folder.
in dev mode it works fine. but when I switch to production mode it dosn't work
no css and js is found.
what could be the problem?
You'll need to enable this behaviour for production. Within config/environments/production.rb, set the following
config.serve_static_assets = true
In your app/config/environments/production.rb, check if the following statement is present:
config.serve_static_assets = true

Precompiled CSS File not found with rails 4 asset pipeline

I'm starting in rails and I've got an application that is working in dev (webrick).
The problem is: the precompiled CSS file is not found in production.
Now I host it on heroku and deploy it. I have a message saying that assets are precompiled (so it's not a compilation error) and everything is by-default for settings.
I've ls the /public/assets folder and everything is in there. I can even cat the application-*.css file and I get the full content I should have.
Now when I try to access the CSS file it gives me an error 404 (even tho it's an auto-generated css link usingĀ <%= stylesheet_link_tag "application", :media => "all" %>). So definetly it's not a problem that I did hardcode the CSS link.
I'm not exactly sure on what would be the next check to perform.
If you're curious on the output, it is currently publicly accessible here.
Try changing the configuration option config.serve_static_assets = false to config.serve_static_assets = true in your config/environments/production.rb if you haven't already done that.
The only thing that fixed it for me in Rails 4 was
config.assets.compile = true
in config/environments/production.rb
This would fall back to the assets pipeline if a precompiled asset is missed, according to the documentation.

Getting Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError

I have an image named pt_homepage_banner1.png.
I ran the task on production
bundle exec rake assets:precompile
and it successfully placed the image file into public/assets folder and made and entry into manifest.yml
Still i am getting exception -
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError
fpt_homepage_banner1.png isn't precompiled
My production.rb settings are
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
Please answer what i am missing. if any clarification regarding the question, please ask
Thank you
I also got the same error,
Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError b-error.png isn't precompiled.
In my app I am calling this image, but in my images/ folder it was not there. So I added it and precompiled it again, so that the file appeared in public/assets folder. But I still gets the same error. So I know that Rails is somewhat stuck with this file, so what I did is I changed the b-error.png to 500.png and used another image and precompiled.
Now it Works!
Set following in config/environments/production.rb
config.serve_static_assets = true
config.assets.compile = true

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