13

I am following thinker's tutorials (https://thinkster.io/angular-rails/) on using angular+rails. everything is fine until I try to use angular-rails-templates to put templates in javascript folder. I am new to rails so I don't know how this gem works. but I did follow the tutorial multiple times and still not working.

To sum up, it seems that the 'templates' module injected into angular app is not compiling those templates into templateCache, or the application.js file is ignoring all the files with .html extension.

here is my code on github: https://github.com/collapsarzhang/demo-projects/tree/master/flapper-news

Kevin Zhang
  • 131
  • 1
  • 3

3 Answers3

21

The solution I found was here: http://ademartutor.azurewebsites.net/angular-rails-templates-gem-error-with-sprockets-3-0-o/

It is a sprockets incompatibility but 2.1.3 works so use this in your Gemfile:

gem 'sprockets', '2.12.3'

(and obviously a bundle update sprockets would be required)

Bijendra
  • 9,467
  • 8
  • 39
  • 66
jcuenod
  • 55,835
  • 14
  • 65
  • 102
  • I too had this issue. Thanks for the fix. I also found that using the puma gem makes it blow up. Any thoughts? – R.J. Robinson Jul 02 '15 at 21:18
  • @R.J.Robinson No clue here I'm afraid. – jcuenod Jul 05 '15 at 19:17
  • I thought update angular-rails-templates to 0.2.0 should be compatible with sprokets 3. But it is not.. – etlds Nov 24 '15 at 20:10
  • I had the same problem one year after this solution was published and it no longer seems to work. The 1.x version of the angular-rails-templates gem requires sprockets 3.x. Maybe installing the 0.x version of the gem and the 2.x version of sprockets would work but I'm just going to continue the tutorial without separate templates since I've spent too much time on this already. – Steve Carey Sep 08 '16 at 00:31
2

It is enough by doing

bundle update

as the library is looking for sprockets ~> 2

QuarK
  • 2,306
  • 1
  • 20
  • 24
0

In case Rails serves a 404 error pointing to your template file, make sure to name your template different than the .js file you are using it in.

The template service needs to be able to distinguish between my_directive.js and my_directive.html compiled to the template cache in .js. You should name your template differently, eg. my_directive_template.html.

David Salamon
  • 2,361
  • 25
  • 30