在“ Ruby on Rails-Tutorial”期间的路由选择错误。 [英] Routing Error during "Ruby on Rails-Tutorial"

查看:77
本文介绍了在“ Ruby on Rails-Tutorial”期间的路由选择错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎有些人遇到了这个问题,但是我在另一个主题中找不到任何解决方案。

It seems like some people here had this problem but I couldn't find any solution in another topic.

我正在做Ruby on Rails的第3章-教程,在静态页面上工作。当我想在本地主机上打开它们时,它在浏览器中给我一个路由错误。

I am doing Chapter 3 of the Ruby on Rails-Tutorial, working on the static pages. When I want to open them on the localhost it gives me a "Routing Error" in the Browser.

我的Ruby当前版本为1.9.3。
My Rails当前版本为3.2。

My Ruby is currently on version 1.9.3. My Rails is currently on version 3.2.

我尝试过:


  • 重新启动服务器

  • 再次保存所有文件

  • 检查static_pages_controller.rb中的所有问题

  • 检查route.rb中的任何问题。

  • 检查static_oages_spec.rb中的任何问题

  • restarting the server
  • saving all the files again
  • checking any issues in the static_pages_controller.rb
  • checking any issues in the routes.rb
  • checking any issues in the static_oages_spec.rb

单个静态页面的HTML代码中也没有错误。而且我在本教程中找不到更多帮助,也在StackOverflow上的其他问题中都找不到。

Also there are no bugs in the HTML code of the single static page. And I can't find any more help in the tutorial, neither in other questions here on StackOverflow.

编辑:

这是来自浏览器的实际错误消息:

This is the actual error message from the browser:


路由错误

Routing Error

没有路线匹配[GET] / static_pages / home尝试运行
耙路,以获取有关可用路线的更多信息。

No route matches [GET] "/static_pages/home" Try running rake routes for more information on available routes.

如果我去 http:// localhost:3000 / static_pages / home ,进入我拥有的三个静态页面之一。

if I go to http://localhost:3000/static_pages/home, to one of three static pages I have.

这是routes.rb:

This is routes.rb:

SampleApp::Application.routes.draw do

get "static_pages/home"

get "static_pages/help"

get "static_pages/about"

end

此外,我尝试了 耙道也在终端中。结果是:

Also, I tried "rake routes" in the terminal, too. This is the result:

home_static_pages GET    /static_pages/home(.:format)  static_pages#home
 help_static_pages GET    /static_pages/help(.:format)  static_pages#help
about_static_pages GET    /static_pages/about(.:format) static_pages#about
      static_pages POST   /static_pages(.:format)       static_pages#create
  new_static_pages GET    /static_pages/new(.:format)   static_pages#new
 edit_static_pages GET    /static_pages/edit(.:format)  static_pages#edit
                   GET    /static_pages(.:format)       static_pages#show
                   PUT    /static_pages(.:format)       static_pages#update
                   DELETE /static_pages(.:format)       static_pages#destroy

这是服务器给我的错误消息:

And this is the error message the server is giving me:

Started GET "/static_pages/home.html" for 127.0.0.1 at 2012-04-03 13:23:54 +0200

ActionController::RoutingError (No route matches [GET] "/static_pages/home.html"):
  actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.3) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.3) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in `call'
  railties (3.2.3) lib/rails/engine.rb:479:in `call'
  railties (3.2.3) lib/rails/application.rb:220:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /Network/Servers/pluto.kayoom.lan/Users/benediktkrebs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
  /Network/Servers/pluto.kayoom.lan/Users/benediktkrebs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
  /Network/Servers/pluto.kayoom.lan/Users/benediktkrebs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'


推荐答案

如果您使用的是Spork,则必须重新运行Spork,以便您的测试将考虑

If you are using Spork you must re-run Spork so your tests will consider the changes in config files like routes.rb, that are pre-loaded with Spork, so are not automatically updated.


  1. 停止Spork(Ctrl + C)

  2. 再次运行Spork(捆绑执行spork)

来源:此是此信息的来源
,在更改预叉加载中包含的文件(例如 routes.rb )之后,您将必须重新启动Spork服务器加载新的Rails环境
如果您认为测试应该通过而失败,请使用Control-C退出Spork服务器,然后重新启动

Source: this is the source of this information "after changing a file included in the prefork loading (such as routes.rb), you will have to restart the Spork server to load the new Rails environment. If your tests are failing when you think they should be passing, quit the Spork server with Control-C and restart it

这篇关于在“ Ruby on Rails-Tutorial”期间的路由选择错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆