Routing Error – No route matches “/say/hello”

Ruby On Rails好的资料似乎不多,去图书馆借了本《应用Rails进行敏捷Web开发》,照例子学一学。用”Rails generate controller say”建个controller,随后又照搬书里说的加了个名为hello的action,启动server,点击”http://localhost:3000/say/hello”一看。咦,不对呀——
不应该显示Template is missing么,怎么出了个routing error?明明是照葫芦画瓢啊,怎么会不一样呢?想了一下,查了一下,没有答案。猜是rails版本变了,所以步骤可能有变化。翻了下书,发现里边说:

Sam Ruby会在我们的wiki上跟踪Rails的修改对本书代码的影响:http://pragprog.wikidot.com/changes-to-rails

点过去在这个页面上发现了如下一段话:

Page 36/45: After cd demo and before rails server (was: ruby script/server), edit config/routes.rb, and uncomment the following line:match ‘:controller(/:action(/:id(.:format)))’

果然是版本不一样导致的问题,估计是默认的routes.rb改了设定吧。鉴于routes.rb这样说:

# This is a legacy wild controller route that’s not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ‘:controller(/:action(/:id(.:format)))’

我就[color=red][b]没有uncomment这一行,而是另起一行[/b]:[/color]

match ‘say/hello’ => ‘say#hello’

问题解决咯!

你可能感兴趣的:(Ruby)