Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails AngularJS和Rails模板引擎_Ruby On Rails_Angularjs_Haml - Fatal编程技术网

Ruby on rails AngularJS和Rails模板引擎

Ruby on rails AngularJS和Rails模板引擎,ruby-on-rails,angularjs,haml,Ruby On Rails,Angularjs,Haml,作为一个铁路工人,我爱我一些火腿或苗条。然而,在使用AngularJS时,我在这两方面都没有太多的运气。有没有一个模板引擎是AngularJS友好的,并且比直接的HTML更简洁?我已经写了关于如何将haml用于带有rails的AngularJS模板,并在一个请求中正确加载所有模板的文章:我正在使用slim用于AngularJS模板。我花了很长时间才弄明白怎么做,但一旦你知道怎么做就很容易了 添加slimgem和bundle安装 确保您有一个模板目录。我的建议是: assets/javascrip

作为一个铁路工人,我爱我一些火腿或苗条。然而,在使用AngularJS时,我在这两方面都没有太多的运气。有没有一个模板引擎是AngularJS友好的,并且比直接的HTML更简洁?

我已经写了关于如何将haml用于带有rails的AngularJS模板,并在一个请求中正确加载所有模板的文章:

我正在使用slim用于AngularJS模板。我花了很长时间才弄明白怎么做,但一旦你知道怎么做就很容易了

添加slimgem和bundle安装

确保您有一个模板目录。我的建议是:

assets/javascripts/templates
然后在config/initializers中创建一个文件。我的就是slim_engine.rb。名字不重要

然后在该文件中包括以下行:

Rails.application.assets.register_engine('.slim', Slim::Template)
下面是我拥有的路由提供程序的一个片段,它使用以下模板之一:

angular.module('customer_app', ['customer_service'])
  .config(['$routeProvider', function($provider) {
    $provider.when('/:customer_id/edit/', { templateUrl: '/assets/customers/edit.html.slim', controller: 'CustomersController' });
  }])
  .config(["$httpProvider", function(provider) {
    provider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content');
  }]);
完整的模板路径是:assets/templates/customers/edit.html.slim


希望这有帮助

你遇到了什么问题?我还没有在AngularJS中广泛使用模板引擎,但我认为,这删除了资产管道中最好的部分fwiw。您需要执行asset_path(“edit.html”)(我相信)以便生产指纹识别工作。