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
Calling Instance Variables Without @
Ruby: Why Are All Coordinates Getting Updated in an Array of Arrays
Rails Object Based Permission/Authorization Engine
How to Split String into 2 Parts After Certain Position
Expressing Conditional Haml Possibly with Ternary Operator
Ssl_Connect Syscall Returned=5 Errno=0 State=Sslv3 Read Server Hello a (Openssl::Ssl::Sslerror)
Why Rails Can Use 'If' as Hash Key But Not in Ruby
Ruby's "Foo = True If !Defined? Foo" Won't Work as Expected
How to Create Zip File Only in Memory in Ruby
Can Nokogiri Use Single Quotes for Attributes on Saving Xml
Ruby: Calculate Time Difference Between 2 Times
Rails, Ruby, How to Count and Sort, Display Top Results
Any Standard Guide for Ruby Win32Ole API
No Such File or Directory @ Rb_Sysopen for External Url/Rails 6.11/Ruby 3
How to Recursively Flatten a Yaml File into a JSON Object Where Keys Are Dot Separated Strings
How Can Same Program in Ruby Accept Input from User as Well as Command Line Arguments
While Executing Gem ... (Argumenterror) Unknown Encoding Name - Cp720