Rails asset pipeline not including required files in application.js manifest

人走茶凉 提交于 2019-12-12 07:30:53

问题


The rails asset pipeline isn't including files required in application.js.

The only javascript file rendered to the browser is application.js, and the require lines are not compiled to include tags as they should be:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require bootstrap
//= require_tree .

;

in config/application.rb I have config.assets.enable = true

I'm using rails 3.2.8, and I've tried ruby 1.9.3-p398 and 2.0.0-p0 installed using rvm.

How do I get application.js to include the files required?

EDIT: It looks like the lock on this question was recently unlocked, and activity has increased. It has been a while since I worked on this, and the code doesn't exist anymore. If I am remembering correctly I reinstalled ruby and rails and that fixed the problem.

Should I close this question? What is the proper procedure in this situation?


回答1:


I answered this here:

Rails 3.2.8 Application.js and Application.css are not working as expcted

Here's the text:

I was also having this issue but with newer versions of Rails and Ruby.

Examining the log, I was being served javascript.js from Rails cache as the server didn't see a change in the file. I went and moved the require lines around (just one) to tell Rails that there's a change in the file and re-compile/use. Wellm that did it for me!

Hope it helps somebody.

Another important finding is to upgrade your sprockets gem in your Gemfile.

I had version 2.2.1 and had issues, after upgrading to 2.2.2, it worked

gem 'sprockets', '2.2.2' 



回答2:


If you are upgrading from 3.0.x - 3.1.x and run in to this issue upgrade to 3.2.x and It may solve this issue.

I recently upgraded an app from 3.0 - 3.1.12 and found the asset manifest would not work using Ruby 1.9.3, Ruby 2.0, or Ruby 2.1.1. I then went ahead and upgraded to 3.2.17 and everything seems to be working correctly using Ruby 2.1.1.

Hopefully this helps anyone else that may run in to this issue upgrading.




回答3:


One common reason for this is that the assets are compiled and found in public/assets, in which case Rails will not recompile them. If you have assets in here, and have not set config.serve_static_assets to false, then Rails will not recompile your assets:

config.serve_static_assets = false

So if you have precompiled stuff in public/assets, either delete them, or add the above line to development.rb




回答4:


Did you copy/paste your bootstrap files into the vendor/assets folder, or into app/assets? The asset pipeline only includes the app/assets folder by default, not lib/assets or vendor/assets. To include vendor/assets in the pipeline, enter this command into your app/assets/javascript/application.js file:

//= require_tree ../../../vendor/assets/javascripts/

To do the same for your CSS files:

*= require_tree ../../../vendor/assets/stylesheets/

I know it says in the comments at the top of the file that any file in the app, lib or vendor folders will be included, but I've found this wasn't the case. I can't explain why, but see here for my source. Try the above commands, or include the bootstrap files in your app/assets folders. Hope that helps.



来源:https://stackoverflow.com/questions/15328569/rails-asset-pipeline-not-including-required-files-in-application-js-manifest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!