Andrey Saleba
Andrey Saleba

Reputation: 2197

Rails: assets are missing in production(No route matches [GET] "/assets/application-12345.css")

I have Rails 4 application. When I'm running it in Development mode, everything works fine, but when I'm running it in Production mode, assets are missing with error from the topic.

Example how I'm using assets:

<%= javascript_include_tag :application %>
<%= stylesheet_link_tag :application, media: 'all' %>

What's the problem? thanks for your time and help.

Error messages are like:

GET http://127.0.0.1:3000/assets/application-562bac274264d04046337005941c14dc9909665bcdecf8739957ad529b009127.js 404 (Not Found)

My application.js and .css files (compiled versions) are in

myproject\public\assets

And application.js and .css files (source ones) are in

myproject\app\assets\javascrips and myproject\app\assets\stylesheets

I'm running app on Windows, if it's important.

Upvotes: 0

Views: 1704

Answers (1)

Richard Peck
Richard Peck

Reputation: 76774

The issue is that in production, assets are precompiled & fingerprinted, hence calling them directly is not going to work. You have to call the filename only:

<%= stylesheet_link_tag :application, media: 'all' %>
<%= javascript_include_tag :application %>

You also need to make sure you keep your stylesheets / javascripts in the appropriate directories. Why you'd put application.css in /javascripts is beyond me.


The reason the above works is because they use the asset_path helper, which allows Rails to pull the appropriate file from a set of relative paths. Rather like the PATH var in operating systems, it means you can call assets which may have been fingerprinted in production.

Upvotes: 1

Related Questions