AngularJS 和 Rails 路由错误 | 路由错误
本文介绍了AngularJS 和 Rails 路由错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述 我正在关注以下教程:https://thinkster.io/angular-rails/
当我进入以下部分时:将前端与资产管道集成,事情就崩溃了;该网站陷入无限循环,并一遍又一遍地产生相同的错误.我已经检查并重新检查了每一步.有人可以帮忙吗:
错误:
在 2015-04-17 11:55:43 -0400 开始 GET "/home/_home.html" for ::1ActionController::RoutingError(没有路由匹配 [GET] "/home/_home.html"):actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'web-console (2.1.2) lib/web_console/middleware.rb:37:in `call'actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'rack (1.6.0) lib/rack/runtime.rb:18:in `call'activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'rack (1.6.0) lib/rack/lock.rb:17:in `call'actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'rack (1.6.0) lib/rack/sendfile.rb:113:in `call'railties (4.2.0) lib/rails/engine.rb:518:in `call'railties (4.2.0) lib/rails/application.rb:164:in `call'rack (1.6.0) lib/rack/lock.rb:17:in `call'rack (1.6.0) lib/rack/content_length.rb:15:in `call'机架 (1.6.0) lib/rack/handler/webrick.rb:89:in `service'/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'渲染/Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.7ms)渲染/Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/routes/_route.html.erb (0.8ms)渲染/Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/routes/_table.html.erb (1.2ms)渲染/Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.3ms)在救援/布局中渲染/Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb (20.6ms)渲染/Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/_markup.html.erb (0.3ms)渲染/Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/style.css.erb 在 layouts/inlined_string (0.3ms)渲染/Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/_inner_console_markup.html.erb 在 layouts/inlined_string (0.5ms)渲染/Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/_prompt_box_markup.html.erb 在 layouts/inlined_string (0.4ms)在布局/javascript中渲染/Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/console.js.erb (17.4ms)在 layouts/javascript 中渲染/Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/main.js.erb (0.3ms)在 layouts/javascript 中渲染/Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/error_page.js.erb (0.6ms)渲染/Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/index.html.erb (33.9ms)
宝石文件:
source 'https://rubygems.org'# Bundle edge Rails 代替: gem 'rails', github: 'rails/rails'宝石导轨",4.2.0"# 使用 sqlite3 作为 Active Record 的数据库宝石'sqlite3'# 对样式表使用 SCSSgem 'sass-rails', '~>5.0'# 使用 Uglifier 作为 JavaScript 资源的压缩器gem 'uglifier', '>= 1.3.0'# 轻松构建 JSON API.阅读更多:https://github.com/rails/jbuildergem 'jbuilder', '~>2.0'# bundle exec rake doc:rails 在 doc/api 下生成 API.gem 'sdoc', '~>0.4.0', 组: :docgem 'angular-rails-templates'# 使用 ActiveModel has_secure_password# gem 'bcrypt', '~>3.1.7'# 使用 Unicorn 作为应用服务器# gem '独角兽'# 使用 Capistrano 进行部署# gem 'capistrano-rails', group::development组:开发,:测试做# 在代码中的任何地方调用 'byebug' 以停止执行并获得调试器控制台宝石'再见'# 在异常页面或使用 访问 IRB 控制台;在视图中gem '网络控制台', '~>2.0'# Spring 通过让您的应用程序在后台运行来加快开发速度.阅读更多:https://github.com/rails/spring宝石春天"结尾
application.js:
//= 需要角度//= 需要 angular-rails-templates//= 需要 angular-ui-router//= require_tree .
routes.rb:
Rails.application.routes.draw 做# 优先级基于创建顺序:首先创建 -> 最高优先级.# 查看您的所有路由如何使用rake 路由"进行布局.# 您可以使用root"路由站点的根目录# root '欢迎#index'根到:'应用程序#angular'结尾application.html.erb:
<头><title>FlapperNews</title><%= stylesheet_link_tag 'application', media: 'all' %><%= javascript_include_tag '应用程序' %><%= csrf_meta_tags %>头部><body ng-app="flapperNews"><div class="row"><div class="col-md-6 col-md-offset-3"><ui-view></ui-view>
</html>
app.js:
angular.module('flapperNews', ['ui.router', 'templates']).config(['$stateProvider','$urlRouterProvider',功能($stateProvider,$urlRouterProvider){$stateProvider.state('家', {网址:'/家',templateUrl: 'home/_home.html',控制器:'MainCtrl'}).state('帖子', {url: '/posts/{id}',templateUrl: 'posts/_posts.html',控制器:'PostsCtrl'});$urlRouterProvider.otherwise('home');}])
app/assets/javascripts/home/_home.html:
<h1>挡板新闻</h1>
<div ng-repeat="在帖子中发帖 | orderBy:'-upvotes'"><span class="glyphicon glyphicon-thumbs-up"ng-click="incrementUpvotes(post)"></span>{{post.upvotes}}<span style="font-size:20px; margin-left:10px;"><a ng-show="post.link" href="{{post.link}}">{{帖子标题}}</a><span ng-hide="post.link">{{帖子标题}}</span></span><跨度><a href="#/posts/{{$index}}">评论</a></span>
<form ng-submit="addPost()"style="margin-top:30px;"><h3>添加新帖子</h3><div class="form-group"><输入类型="文本"类=形式控制"占位符=标题"ng-model="title"></input>
<div class="form-group"><输入类型="文本"类=形式控制"占位符=链接"ng-model="link"></input>
<button type="submit" class="btn btn-primary">发布</button></表单>
解决方案
遇到了同样的问题.链轮问题.
此处的解决方案:Angular Rails 模板无法正常工作
在这里:http://www.ademartutor.com/angular-rails-templates-gem-error-with-sprockets-3-0-o/
I am following the tutorial at: https://thinkster.io/angular-rails/
and when I get to the section: Integrating the Front-end with the Asset Pipeline, things break; the site gets stuck in an infinite loop and keeps producing the same error over and over. I've checked and rechecked each step. Could someone please help:
Error:
Started GET "/home/_home.html" for ::1 at 2015-04-17 11:55:43 -0400
ActionController::RoutingError (No route matches [GET] "/home/_home.html"):
actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
web-console (2.1.2) lib/web_console/middleware.rb:37:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
rack (1.6.0) lib/rack/content_length.rb:15:in `call'
rack (1.6.0) lib/rack/handler/webrick.rb:89:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
Rendered /Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.7ms)
Rendered /Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/routes/_route.html.erb (0.8ms)
Rendered /Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/routes/_table.html.erb (1.2ms)
Rendered /Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.3ms)
Rendered /Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (20.6ms)
Rendered /Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/_markup.html.erb (0.3ms)
Rendered /Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.3ms)
Rendered /Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.5ms)
Rendered /Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.4ms)
Rendered /Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/console.js.erb within layouts/javascript (17.4ms)
Rendered /Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/main.js.erb within layouts/javascript (0.3ms)
Rendered /Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.6ms)
Rendered /Users/MacKenzie/.rvm/gems/ruby-2.2.0/gems/web-console-2.1.2/lib/web_console/templates/index.html.erb (33.9ms)
Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'angular-rails-templates'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
application.js:
//= require angular
//= require angular-rails-templates
//= require angular-ui-router
//= require_tree .
routes.rb:
Rails.application.routes.draw do
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
# root 'welcome#index'
root to: 'application#angular'
end
application.html.erb:
<!DOCTYPE html>
<html>
<head>
<title>FlapperNews</title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
<%= csrf_meta_tags %>
</head>
<body ng-app="flapperNews">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<ui-view></ui-view>
</div>
</div>
</body>
</html>
app.js:
angular.module('flapperNews', ['ui.router', 'templates'])
.config([
'$stateProvider',
'$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'home/_home.html',
controller: 'MainCtrl'
})
.state('posts', {
url: '/posts/{id}',
templateUrl: 'posts/_posts.html',
controller: 'PostsCtrl'
});
$urlRouterProvider.otherwise('home');
}])
app/assets/javascripts/home/_home.html:
<div class="page-header">
<h1>Flapper News</h1>
</div>
<div ng-repeat="post in posts | orderBy:'-upvotes'">
<span class="glyphicon glyphicon-thumbs-up"
ng-click="incrementUpvotes(post)"></span>
{{post.upvotes}}
<span style="font-size:20px; margin-left:10px;">
<a ng-show="post.link" href="{{post.link}}">
{{post.title}}
</a>
<span ng-hide="post.link">
{{post.title}}
</span>
</span>
<span>
<a href="#/posts/{{$index}}">Comments</a>
</span>
</div>
<form ng-submit="addPost()"
style="margin-top:30px;">
<h3>Add a new post</h3>
<div class="form-group">
<input type="text"
class="form-control"
placeholder="Title"
ng-model="title"></input>
</div>
<div class="form-group">
<input type="text"
class="form-control"
placeholder="Link"
ng-model="link"></input>
</div>
<button type="submit" class="btn btn-primary">Post</button>
</form>
解决方案
Ran into the same issue. sprockets issue.
solution here: Angular Rails Templates just not working
and here: http://www.ademartutor.com/angular-rails-templates-gem-error-with-sprockets-3-0-o/
这篇关于AngularJS 和 Rails 路由错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
08-26 00:18