【发布时间】:2010-10-20 12:17:38
【问题描述】:
我刚刚升级到 Rails 3,并决定使用虚拟/沙盒应用程序试一试。奇怪的是我似乎无法获得任何条路线!
这是我的问题:
[cobychapple@shiva:Dev]$rails new TestApp
create
create README
create Rakefile
...
[cobychapple@shiva:Dev]$cd TestApp/
[cobychapple@shiva:TestApp]$rails g scaffold widget name:text
invoke active_record
create db/migrate/20101020115518_create_widgets.rb
create app/models/widget.rb
...
[cobychapple@shiva:TestApp]$rake db:migrate
(in /Users/cobychapple/Dev/TestApp)
== CreateWidgets: migrating ==================================================
-- create_table(:widgets)
-> 0.0015s
== CreateWidgets: migrated (0.0016s) =========================================
[cobychapple@shiva:TestApp]$rake routes
(in /Users/cobychapple/Dev/TestApp)
widgets GET /widgets(.:format) {:action=>"index", :controller=>"widgets"}
widgets POST /widgets(.:format) {:action=>"create", :controller=>"widgets"}
new_widget GET /widgets/new(.:format) {:action=>"new", :controller=>"widgets"}
edit_widget GET /widgets/:id/edit(.:format) {:action=>"edit", :controller=>"widgets"}
widget GET /widgets/:id(.:format) {:action=>"show", :controller=>"widgets"}
widget PUT /widgets/:id(.:format) {:action=>"update", :controller=>"widgets"}
widget DELETE /widgets/:id(.:format) {:action=>"destroy", :controller=>"widgets"}
[cobychapple@shiva:TestApp]$rails s -d
=> Booting WEBrick
=> Rails 3.0.1 application starting in development on http://0.0.0.0:3000
[cobychapple@shiva:TestApp]$
所以现在我转到我的浏览器并访问http://localhost:3000/widgets
Rails 说: 路由错误:没有路由匹配“/widgets”
我不明白 rake 路由如何显示路由存在,然后服务器将无法匹配它。我用谷歌搜索了一大堆,似乎有几个人在 rails 3 中有路由问题,但没有一个人像我得到的那样明显基本。我敢肯定,我只是错过了一些小事,但我一生都无法弄清楚!有什么建议吗?
我的 routes.rb 文件只是脚手架生成的 + 文档 cmets:
TestApp::Application.routes.draw do
resources :widgets
# The priority is based upon order of creation:
# skip the rest of the comments...
end
【问题讨论】:
-
你有文件 app/controller/widgets_controller.rb 吗?
-
我做了和你一样的步骤,而且没有问题。奇怪...
-
是的... app/controllers/widgets_controller.rb 存在并由脚手架脚本生成。感谢您的检查!
标签: ruby-on-rails ruby-on-rails-3 routes