我正在做这个教程:https://www.honeybadger.io/blog/2013/12/11/beginners-guide-to-angular-js-rails?utm_source=rubyweekly&utm_medium=email,我对角度路线有很大的问题。它们完全被忽略了。
这里有一些代码:
应用程序/资产/ JavaScript的/ main.js.coffee
@restauranteur = angular.module('restauranteur', [])
@restauranteur.config(['$routeProvider', ($routeProvider) ->
$routeProvider.
when('/restaurants', {
templateUrl: '../templates/restaurants/index.html',
controller: 'RestaurantIndexCtrl'
}).
when('/restaurants/:id', {
templateUrl: '../templates/restaurants/show.html',
controller: 'RestaurantShowCtrl'
}).
otherwise({
templateUrl: '../templates/home.html',
controller: 'HomeCtrl'
})
])
routes.rb中:
Restauranteur::Application.routes.draw do
root to: 'static_pages#index'
end
application.html.erb:
<!DOCTYPE html>
<html ng-app="restauranteur">
<head>
<title>Restauranteur</title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application', controller_name %>
<%= csrf_meta_tags %>
</head>
<body>
<div ng-view>
<%= yield %>
</div>
</body>
</html>
配置/初始化/ assets.rb:
Rails.application.config.assets.version = '1.0'
Rails.application.config.assets.precompile += %w( static_pages.js )
公共/模板/餐馆/ index.html中:
<a href="/#">index</a>
<ul ng-repeat="restaurant in restaurants">
<li><a ng-click="viewRestaurant(restaurant.id)">{{ restaurant.name }}</a></li>
</ul>
每次去http://localhost:3000/#/restaurants
,我都能看到餐馆指数,我看到的只有:
StaticPages#索引
在app / views / static_pages / index.html.erb;
中找到我任何帮助都将非常感谢!