Rails cannot include AngularJS

I am following this tutorial , and although adding it to the Gem file and installing it, it works great. At that moment, when I try to include it in the application.js file, I get the following error when loading:

throw Error("Sprockets::FileNotFound: couldn't find file 'angular'\n  (in /my/path/to/rails/app/assets/javascripts/application.js:13)")

The application.js file looks like this (starting at line 13):

//= require angular
//= require jquery
//= require jquery_ujs
//= require jquery.ui.autocomplete
//= require bootstrap
//= require pusher.min.js
//= require pusher_setup
//= require_directory .

So my question is: how can I successfully include AngularJS in a Rails project?

I am currently using Rails 3.2.2 and Ruby 1.9.3.

+5
source share
4 answers

I had the same problem. I solved it as follows.

1) In my case, it was //= require_tree .missing from the file application.js.. so I added it.

2) Apache ( webrick, )

+5

-.

angular javascripts vendor/assets/javascripts, , , //= require angular. , , , , , .

require_tree ., , , .

, angular jQuery (jQuery-lite), jQuery, , .

//= reqiure angular 
//= require jquery

- ,

//= require jquery
//= require angular

, , , Backbone.js Underscore, Underscore Backbone ..

require, , , //= require_tree ./controllers . , require_tree .

+5

gemfile, :

group :assets  do
   gem 'angularjs-rails'
end

: , :

ex:

gem 'angularjs-rails'

+4

- , . //= require angular

group :assets do
//= require angular
end

However, I still got the same error. After a short search, I found out that for some reason it should be added outside the asset group . Now all is well. Not sure if this is the best way, although I no longer get this error.

+2
source

All Articles