Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

Rails 4 compiling vendor assets but not application.js and application.css

I have an old Rails 3 app I'm upgrading to Rails 4. Sprockets seems to be adding suffixes and working with the Javascript I have in /vendor, but my assets/javascripts/application.js, assets/stylesheets/application.css, and assets/images/... aren't working. In the HTML, I can see they have suffixes, but they error when trying to load.

For example, this works: 0.0.0.0:8080/assets/jquery-1.8.3.min-95a3734fc817813c8ba0cd3438033917a3863503b2ca20e8b30a7f61b031576f.js

But this doesn't: 0.0.0.0:8080/assets/application-7437324e57ae6cb54f03eaa608a99381fca68ad72ed2009f8fccd49f41f34bac.css

However, this works: 0.0.0.0:8080/assets/application.css

Images also don't work. When I do image_tag it gives Sprockets::Rails::Helper::AssetNotPrecompiled error.

Should Rails 4 be adding suffixes when in local development mode?

If yes, what's the problem with Rails 4 and Sprockets - do I need to change my config somehow?

question from:https://stackoverflow.com/questions/65855143/rails-4-compiling-vendor-assets-but-not-application-js-and-application-css

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Those "suffixes" are hashes and meant to be unique to the contents of the file. Mostly this is useful in production as a caching technique. It's been a long time since I moved apps from 3 to 4. Modern rails apps are using webpack for a lot of this, but the asset pipeline still works for now.

My recollection is that the hashes weren't being generated in development mode. You should read the documentation on precompiling assets if you haven't already.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...