ruby-on-rails – AngularJS和Rails路由错误

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – AngularJS和Rails路由错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在以下教程: https://thinkster.io/angular-rails/

当我到达这个部分时:将前端与资产管道整合,事情就会崩溃;该网站被困在无限循环中,并且一直反复产生相同的错误.我已经检查并重新检查每一步.有人可以帮忙:

错误

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');

}])

应用程序/资产/ JavaScript的/家/ _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>

解决方法

原文链接:https://www.f2er.com/ruby/266410.html

猜你在找的Ruby相关文章