【发布时间】:2013-05-13 15:26:01
【问题描述】:
我正在创建一个简单的建议框应用程序(学习 Rails),当我转到在我的本地机器上运行的“/suggestion-boxes”时遇到以下 Rails 路由错误(localhost:3000)
"路由错误
没有路线匹配 [GET] "/suggestion-boxes"
在我的 routes.rb 文件中我有:
SuggestionBoxApp::Application.routes.draw do
resources :suggestion_boxes
end
这是我运行 rake 路由时得到的结果:
suggestion-box-app$ rake routes
suggestion_boxes GET /suggestion_boxes(.:format) suggestion_boxes#index
POST /suggestion_boxes(.:format) suggestion_boxes#create
new_suggestion_box GET /suggestion_boxes/new(.:format) suggestion_boxes#new
edit_suggestion_box GET /suggestion_boxes/:id/edit(.:format) suggestion_boxes#edit
suggestion_box GET /suggestion_boxes/:id(.:format) suggestion_boxes#show
PUT /suggestion_boxes/:id(.:format) suggestion_boxes#update
DELETE /suggestion_boxes/:id(.:format) suggestion_boxes#destroy
但是,如果我将路由文件修改为
SuggestionBoxApp::Application.routes.draw do
get "suggestion-boxes" => "suggestion_boxes#index"
end
然后页面“/suggestion-boxes”根据我的 SuggestionBoxesController 中的索引操作显示。
我尝试重新启动我的服务器,但这没有任何影响。虽然我当然可以使用 GET,但这个错误没有任何意义,我想了解是什么原因造成的。
非常感谢任何见解。
【问题讨论】:
标签: ruby-on-rails routing