我将我的角应用程序放入rails app上的新ruby中。我注意到的是没有任何观点被渲染出来。我只看到正在渲染的布局。我也没有收到任何错误。我的2个视图(home.html和about.html)和list.json位于公共文件夹中。如果您需要应用程序中的更多代码,请告诉我们。
我的应用程序布局如下:
<!DOCTYPE html>
<html>
<head>
<title></title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<button data-target=".nav-collapse" data-toggle="collapse" class="btn btn-navbar" type="button">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="/home" class="brand"><img src="assets/tool-box.png" /> Dev Tool Chest</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li class="active">
<a href="/home">Home</a>
</li>
<li class="">
<a href="./about">About</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
<div id="view" ng-view></div>
</div>
</body>
</html>
我的应用程序控制器如下:
class ApplicationController < ActionController::Base
protect_from_forgery
def index
render :layout => 'application', :nothing => true
end
end
我的JS资产管道如下:
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require angularmin.js
//= require angularstrap.min.js
//= require toolsapp.js
toolsapp.js看起来像这样
var tools = angular.module("tools", ['$strap.directives'])
tools.config(function($routeProvider) {
$routeProvider.when('/home', {
templateUrl: 'home.html',
controller: 'HomeController'
});
$routeProvider.when('/about', {
templateUrl: 'about.html',
controller: 'AboutController'
});
$routeProvider.otherwise({ redirectTo: '/home' })
});
tools.controller("HomeController", function($scope, fetchData) {
fetchData.then(function(data){
$scope.record = data;
$scope.typeahead = function(){
var allNames = [];
for(var i=0;i<$scope.record.length;i++){
allNames.push($scope.record[i].name)
}
return allNames;
}
});
$scope.clearSearch = function(){
$scope.search = "";
$scope.name2 = "";
}
$scope.name2 = "";
$scope.search = "";
});
tools.controller("AboutController", function($scope) {
});
tools.factory('fetchData', ['$http', function($http){
var Url = "list.json";
var list = $http.get(Url).then(function(response){
return response.data;
});
return list;
}]);
tools.filter('unique', function () {
return function (items, filterOn) {
if (filterOn === false) {
return items;
}
if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) {
var hashCheck = {}, newItems = [];
var extractValueToCompare = function (item) {
if (angular.isObject(item) && angular.isString(filterOn)) {
return item[filterOn];
} else {
return item;
}
};
angular.forEach(items, function (item) {
var valueToCheck, isDuplicate = false;
for (var i = 0; i < newItems.length; i++) {
if (angular.equals(extractValueToCompare(newItems[i]), extractValueToCompare(item))) {
isDuplicate = true;
break;
}
}
if (!isDuplicate) {
newItems.push(item);
}
});
items = newItems;
}
return items;
};
});
答案 0 :(得分:1)
我的建议是:
创建家庭控制器:
<强> home_controller.rb 强>
class HomeController < ApplicationController
def index
end
def about
end
end
将您的观看次数移至app/views/home
文件夹。
添加以下路线:
的routes.rb
get 'about', to: "home#about"
root to: 'home#index'
从application_controller
:
def index
render :layout => 'application', :nothing => true
end
在您的布局中添加yield
:
<div class="container">
<div id="view" ng-view>
= yield
</div>
</div>
因此,当您转到localhost:3000和localhost:3000 / about时,您的家和视图将会在您的布局中呈现。