24

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?

everett1992
  • 2,351
  • 3
  • 27
  • 38

4 Answers4

13

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' 
Community
  • 1
  • 1
lsaffie
  • 1,764
  • 1
  • 17
  • 22
3

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.

  • I can confirm this seems to have done the trick - upgraded from ruby 1.9.3 to 2.1.5 and things broke on rails 3.2.6, fixed when I upgraded to rails 3.2.21. – Kevin Qi Jan 11 '15 at 23:21
  • Also seemed to work for me. May be related to sprockets above (Installing sprockets 2.2.3 (was 2.1.4)) – pixelearth Dec 25 '15 at 07:49
1

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

Houen
  • 1,039
  • 1
  • 16
  • 35
0

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.

Community
  • 1
  • 1
Richie Thomas
  • 3,073
  • 4
  • 32
  • 55
  • This question was recently reopened, I don't have the code anymore so I can't do diagnostics anymore. What is proper etiquette in this situation? – everett1992 Oct 24 '13 at 23:02
  • Sorry, proper etiquette in terms of what? Awarding an answer, up/downvoting, or something else? If you mean one of those things, I would guess the choice is yours, since the question is yours. Your actions indicate your opinion of the answer. :-) – Richie Thomas Oct 25 '13 at 00:09