新手问题 Routing Error, 但是 rake routes 可以看到地址是正確的。

1272729223 · 2012年09月05日 · 最后由 1272729223 回复于 2012年09月05日 · 2855 次阅读

routes.rb:

resources :articles, path: "news"

rake routes打印的結果:

articles GET    /news(.:format)           articles#index
             POST   /news(.:format)           articles#create
 new_article GET    /news/new(.:format)       articles#new
edit_article GET    /news/:id/edit(.:format)  articles#edit
     article GET    /news/:id(.:format)       articles#show
             PUT    /news/:id(.:format)       articles#update
             DELETE /news/:id(.:format)       articles#destroy

訪問的地址:

http://localhost:3000/news

以下是報錯信息:

Routing Error
No route matches {:action=>"show", :controller=>"articles"}
Try running rake routes for more information on available routes. 

news 的单复数是一样的,你试试看加上 singular 参数:

map.resources :articles, :as => "news", :singular => "news"

我找到了,是我在 view 裡面寫錯了一個 path

需要 登录 后方可回复, 如果你还没有账号请 注册新账号