Trying to Use 'Angular Rails Templates' gem

天大地大妈咪最大 提交于 2019-12-12 02:47:15

问题


so, I'm trying to use the templates folder in AngularJS instead of the 'views' folders that you'd normally use in Rails.

Things work great when I write everything in html, but what if I want to write things in slim, and still work with AngularJS templates, instead of rails Views?

The answer: angular rails templates

Unfortunately... it doesn't quite work. It adds this at the beginning of my page before it successfully renders the rest from slim into html:

Angular Rails Template // source: app/assets/templates/books/indexx.html.slim

angular.module("templates").run(["$templateCache", function($templateCache) { $templateCache.put("books/indexx.html", '

  //the rest of my webpage, beautifully rendered from slim to html****


') }]); 

So it's close, but no cigar. I've seen other work arounds for this, involving going into your config folder in rails and adding files and so on... but none of them seemed to work. Any direction I should be looking here? My main goal is just be able to use 'templates' in AngularJS (mainly so I can use the ui router) but be able to write them in SLIM instead of html.

EDIT: Hmm... just restarted my server and now everything works. What's really scary is that everything works without the 'angular rails templates' gem... and also without any special config file in config/initializers/angular_helper.rb that looks like: # For Slim, remember also to add gem to Gemfile Rails.application.assets.register_engine('.slim', Slim::Template)

All I had to do was call the filename.html.slim in my ui-router...and everything works. RESTART THE SERVER I guess is the lesson

Sorry for wasting Stackoverflow space with this


回答1:


When you use Angular Rails Template gem, you have to load your templates over

    templateURL: 'foo/bar/index.html'

when you path is app/assets/templates/foo/bar/index.html.



来源:https://stackoverflow.com/questions/24685764/trying-to-use-angular-rails-templates-gem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!