在rails项目中,我只想使用rails应用程序的控制器和模型。为此,我使用angularjs
。我把我的angularjs文件在assets/angular
目录,我路由url和设置模板从app.js
在angular。通过application_controller.rb
中的以下代码了解我停用rails视图:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def index
render :layout => 'application', :nothing => true
end
end
config/routes.rb
:
root to: 'application#index'
知道,当我运行服务器和项目在localhost:3000
上运行时,我的脚本不加载,<head>
的html文件是空的。
<html>
<head>
</head>
<body>
<pre style="word-wrap: break-word; white-space: pre-wrap;">
</pre>
</body>
</html>
这个问题是关于资产管道,js
不加载。我怎样才能解决这个问题?
我有angular的代码:
asset/javascripts/angular/app.js.erb
:
'use strict';
angular.module('app', ['ngResource'])
.config(['$routeProvider', function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {controller: 'ForumIndexController', templateUrl: '<%= asset_path('templates/index.html') %>'})
.otherwise({redirectTo: '/'});
}
]);
view/layout/application.html.erb
:
<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
<title>SimpleForum</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div class="container">
<div ng-view></div>
</div>
</body>
</html>
assets/javascripts/application.js
:
//= require jquery
//= require jquery_ujs
//= require angular.min
//= require angular-resource.min
//= require ../angular/app
//= require_tree ../angular
如何设置rails应用程序加载脚本?
有解决这个问题的办法吗?
我认为你不需要…因为它和manifest在同一层。
//= require angular/app
//= require_tree angular