Ruby on rails Rails 3.2路由错误

Ruby on rails Rails 3.2路由错误,ruby-on-rails,webrick,Ruby On Rails,Webrick,在我使用Rails的第一种方法中,我只是创建了一个voidSayController和statichello.rhtml视图,但是当页面http://localhost:3000/say/hellostarted返回给我一个路由错误,如下所示: No route matches [GET] "/say/hello" Try running rake routes for more information on available routes. Rails版本:3.2.6似乎您没有在confi

在我使用Rails的第一种方法中,我只是创建了一个void
SayController
和static
hello.rhtml
视图,但是当页面
http://localhost:3000/say/hello
started返回给我一个路由错误,如下所示:

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

Rails版本:3.2.6

似乎您没有在
config/routes.rb
文件中添加for
hello

YourApp::Application.routes.draw do
  match 'say/hello' => 'say#hello', :as => :hello
end
这将匹配到控制器的路径
say/hello
(前面的部分
)和动作
hello
(后面的部分

:as=>:hello
使其成为一个路径,因此您可以在应用程序中将其称为
hello\u path


错误消息告诉您运行
rake routes
(从控制台),这将显示应用程序中的路径。

您应该在
配置/routes.rb中有一些内容来定义该路径。尝试:

match 'say/hello' => 'say#hello', :as => 'say_hello'
转到
localhost:3000/say/hello
另请查看以下文档:


我假设,控制器:和动作:你好

将以下内容添加到config/route.rb

 get 'say/hello' => 'Say#hello'

那么,“rake路由”的输出是什么呢?很好!但我不明白每次创建控制器时是否都要运行该任务?如果您在控制器中创建一个新方法并希望路由到它,则必须在config/routes.rb中定义该方法。现在我遇到了模板缺失错误:缺少模板say/hello,application/hello with{:locale=>[:en],:formats=>[:html],:handlers=>[:erb,:builder,:coffee]}搜索:“:”C:/rails\u proj/demo/app/views“这是rails中模型视图控制器的工作方式。你有一个带有动作Hello的控制器,现在你需要一个在Say里面的视图Hello。该应用程序查看app/views/application/或app/views/say/以在web上显示类似hello.html.erb的内容。尝试创建这样的html文件。