Rails 404 Error for Stylesheet or JavaScript Files

Rails 404 error for Stylesheet or JavaScript files

The error message looks like your Rails app is getting the request for a static file. Rails 3 does not serve static files by default, since the webserver can do so much better. You should check your webserver's configuration. It should be configured to first look, if a static file exists in the public directory for a request and only forward the request to the Rails app, if there's no static file.

Alternatively, you can enable Rails to also serve static files with config.serve_static_assets = true in config/environments/production.rb. However, this is not recommended in production, since you really shouldn't waste processing resources of a Rails app just for serving static files. Better tell the webserver to do so.

Rails 3.2.2 getting a 404 on stylesheets and js assets after deployment with capistrano

not quite sure how to do this (I'm not sure on the etiquette of answering your own question) but I may have resolved the prpoblem, basically, I figured that although the nginx server was restarting, the unicorn server was not (or if so the effects were not taking effect). I found the solution to this post Restart Unicorn issue (capistrano) seems to have done the trick. now i just need to figure out how to wire it into my code!

Error 404 (Not Found) for assets in Rails 6 in Dev

Using Rails-UJS in JS modules (Rails 6 with webpacker)

Your application.js needs to be moved to a different folder for webpacker to be able to use it.

app/javascript/packs/application.js

Failed to load resource: the server responded with a status of 404 (Not Found) javascript/application.js

Locally, javascript files should be under app/assets/javascripts. They will be compressed, minified and copied into public during assets compilation (deployment)

Looks like there's no js files under /public/javascripts hence the 404 error you are getting.

It's also worth checking that you are starting the app in development mode. Otherwise, rails will look into public for js and css files.

See https://guides.rubyonrails.org/asset_pipeline.html#asset-organization for more details.

Rails assets rendering 404 out of the box

i think you need to change your javascript and stylesheet tag like this. it fetches details from application.js and application.css not from default ones

<%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

Javascript asset pipeline: 404 error - How to include Google analytics code in Rails?

Rails system needs to know pre-compilation of that file.
By default it works with application.js but if you create a new manifest file, you have to include it.

In config/initializers/assets.rb or production.rb add the below line:

Rails.application.config.assets.precompile << ['google-analytics.js']


Related Topics



Leave a reply



Submit