In my application.js file, I have the following:
//= require jquery
//= require vendor
When I load up a Rails server with rails s the application.js file that is served still has the require statements at the top. I expect it to remove these lines and load the jquery file separately.
I'm using Rails 3.2.19. My RAILS_ENV is not set.
Though I'm not entirely sure that what you're doing doesn't work, I typically use //= require [name of js file]. e.g. //= require bootstrap.js when bootstrap.js is inside the vendors/javascript folder.
Are you using an old version of Ruby? Maybe something from before 1.9.3? I had similar before problems when upgrading Rails without upgrading Ruby.
Bug with sprockets 2.2.1
Updated to sprockets 2.2.2 (via bundle update sprockets) and it now works
Related
I just upgraded our Rails app from 4.2.5 to 5.0.1
The rails server boots up fine but when I try to load a page I'm now getting the error:
Sprockets::FileNotFound - couldn't find file 'jquery-ui/autocomplete' with type 'application/javascript'
When I run bundle I can see
Using jquery-rails 4.2.2
Using jquery-ui-rails 6.0.1
change the line in application.js
from
//= require jquery-ui/autocomplete
to
//= require jquery-ui/widgets/autocomplete
Seems the file paths have changed. According to the gem readme:
Warning:
Due to directory structure changes between jQuery UI 1.10, 1.11, and 1.12, if you use version is lower than 6.0, you will have to use a different naming for the files to require, please check following links for more information: for 5.0 users, for 4.2 users.
My case was exceptionally weird. When I set up my old legacy app in Ubuntu 20 it worked fine until I rebooted my laptop. After that it displayed the error under question. I checked that I use correct RVM gemset with correct ruby version, gems were bundled as they should have.
When I changed the
//= require jquery-ui/autocomplete
to
//= require jquery-ui/widgets/autocomplete
this line passed and worked fine, but next ones starting causing problems.
Eventually I had to change all the following lines:
//= require jquery-ui/widgets/autocomplete
//= require jquery-ui/widgets/datepicker
//= require jquery-ui/widgets/droppable
EXCEPT THIS:
//= require jquery-ui/effect and I have no idea why this single line works while others don't :/
I'm following this tutorial: https://thinkster.io/angulartutorial/angular-rails/ and everything went well till the part where I had to arrange my angular code with folders in the rails assets pipeline javascripts and use the gem 'angular-rails-template' (https://github.com/pitr/angular-rails-templates) to reach them.
I've installed the gem through the Gemfile and I'm getting a "couldn't find file 'angular-rails-templates'" error even though I've required the file in the application.js:
//= require angular
//= require angular-rails-templates
//= require angular-ui-router
//= require_tree .
Any suggestions?
Apperantly I was sure that I restarted the server, which I didn't. If anyone encouter this problem try the old fashioned solution to fix it.
I'm developing a rails (3.2) application using bootstrap. This application includes a dropdown menu that insists in not working when I run the app in development mode. The funny thing is that it worked before.
This is my application.js:
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_tree .
This issue might happen if the assets are precompiled during development. During development the unminifed files for bootstrap are included and the resource containing the minified version of all the javascripts (/assets/application.js?body=1) should be empty. If the assets are precompiled (rake assets:precompile) applications.js will be generated and code duplication will occur.
Cleaning the precompiled assets should fix the issue (rake assets:clean)
I just installed the rails-backbone gem and then rails g backbone:install.
I see a list of javascript references to backbone on application.js but it does not copy them to the project and I'm not sure if this is normal.
//= require backbone
//= require backbone_rails_sync
//= require backbone_datalink
//= require backbone/myapp
If this is normal, where is it possible to find backbone_rails_sync and backbone_datalink. I'm afraid that by simple searching will maybe not find the same version tested for this gem?
These files are inside the gem and served through Rails Asset Pipeline.
You could find them in the gem souce.
I'm using rails 3.2, but I'm compiling my coffee files with CodeKit.
I still want my coffee files to live inside 'assets', but each time I restart rails, it finds them in there and tries to compile them itself.
My files live in /assets/cafe/myscript.coffee, and codekit compiles them into /assets/javascripts/myscript.js
The coffee-rails gem is already commented out in my gemfile (when rails tries to (re) compile it it gives "throw Error("LoadError: no such file to load -- coffee_script)" - though I really dont want it to even try compiling.
Setting "config.assets.compile = false" in application.rb results in "application.js isn't precompiled"
you should probably just configure your sprockets manifest to not require the whole tree.
edit app/assets/javascripts/application.js
typically it looks like this:
//= require jquery
//= require jquery_ujs
//= require_tree .
change that to
//= require jquery
//= require jquery_ujs
//= require myscript
An (inferior) workaround is to put my coffeescripts inside "App" rather than "assets" (so one more branch up the tree.)
This sucks because it's not where they should go, but at least it does put it outside rails' stalker-tendencies to find coffeescript files anywhere in assets and try to compile them.