Sprockets::FileNotFound in Application#angular - ruby-on-rails

I'm working through the thinkster Angular-Rails tutorial (https://thinkster.io/angular-rails), and encounter the following error trying to install Devise:
Sprockets::FileNotFound in Application#angular
couldn't find file 'angular-devise'(in /app/assets/javascripts/application.js:2)
I have installed Devise gem, restarted the server, installed angular-devise and injected Devise module into my app. Guidance on how to troubleshoot appreciated!

Instead of angular-devise use AngularDevise/lib/devise but it must be placed after
angular-rails-templates
please see the following order
//= require angular
//= require angular-rails-templates
//= require AngularDevise/lib/devise

Ravi's approach worked for me.
The step from the thinkster tutorial reads like this:
require angular-devise in application.js after angular
Seems like the wording of that step could be improved.
Note that the AngularDevise folder contains a bower.json file that points to lib/devise.js. So this will also work:
//= require AngularDevise
Doing it this way is more consistent with how other packages are referenced in the application.js file. And it insulates application.js from future changes to the directory structure/naming inside the AngularDevise directory.

Related

Can't make javascripts work in Rails app in production

I'm on Rails 5.1 using Bootstrap 4.0.0-beta.
I am having difficulties deploying to production (development works fine, without Yarn).
Yarn is working and I have package.json and node_modules.
I have been following Nithin's walkthrough. My styles are working; however, my javascript does not work.
I've tried addind popper.js using //= require popper.js/dist/umd/popper, but this hasn't helped.
None of my javascript works. For example, all dropdowns are completely dead.
Does anyone have any suggestions?
UPDATE
I checked out in development with Yarn and it failed. So all the files are added to the head, but do not work!
Any suggestions are appreciated!
Your format is wrong here:
\\= require popper.js/dist/umd/popper
Check you're using the correct folder for popper.js, and -- if that's correct --
use the following format:
//= require popper.js/dist/umd/popper
Hope that helps.
Finally, I got the Bootstrap working! I removed it with yarn remove bootstrap and reinstalled it with yarn add bootstrap#4.0.0-alpha.6
Then I added //= require tether/dist/js/tether to application.js right upon //= require bootstrap/dist/js/bootstrap
Also I removed //= require popper.js/dist/umd/popper cause the alpha version seems to be working fine without it.

Rails 5: Sprockets::FileNotFound - couldn't find file 'jquery-ui/autocomplete' with type 'application/javascript'

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 :/

Rails 4 Couldn't find file 'angular-rails-templates'

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.

Rails Asset Pipeline not compiling assets

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

Rails and codekit - how to disable rails coffescript compilation

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.

Resources