[英]Rails resourceful routes all point to index action?
我正在運行Rails 2.3.8。
我在route.rb文件中設置了map.resources :users
。
當我運行rake routes
它顯示:
users GET /users(.:format) {:action=>"index", :controller=>"users"}
GET /users(.:format) {:action=>"index", :controller=>"users"}
new_user GET /users/new(.:format) {:action=>"index", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"index", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"index", :controller=>"users"}
GET /users/:id(.:format) {:action=>"index", :controller=>"users"}
GET /users/:id(.:format) {:action=>"index", :controller=>"users"}
/:controller/:action/:id
/:controller/:action/:id(.:format)
抱歉,格式化。 但是重點是... 1)我的“ PUT”,“ POST”等路線在哪里?,2)為什么所有內容都指向index
?
任何幫助將不勝感激...謝謝!
更新:完整的路由文件:
ActionController::Routing::Routes.draw do |map|
map.login "login", :controller => "user_sessions", :action => "new"
map.logout "logout", :controller => "user_sessions", :action => "destroy"
map.resources :users
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
而且我的users_controller具有所有常用的新建,創建,顯示,編輯,更新方法...
我認為您有兩個問題之一: rake routes
的輸出已被終端屏幕破壞,或者您的路徑被其他已安裝的東西(如Rails引擎)覆蓋。
首先很容易檢查。 聽起來您已經完成了基本的用戶支架設置(沒有太多其他設置),因此啟動script/server
,請轉到http:// localhost:3000 / users / new 。 如果您看到新的用戶頁面,則說明終端顯示有問題,但是您的路線還可以。 但是,如果看到用戶索引頁面,請繼續執行下一步。
仔細檢查您上面發布的路由文件確實是您應用程序的文件。 這聽起來很荒謬,但是在某些編輯器中,打開錯誤的文件很容易。 例如,在TextMate中,如果供應了一些gems並通過Command-T打開routes文件,則可以有多個route.rb文件可供選擇。
如果確定查看的是正確的路由文件,則下一步是檢查應用程序中是否有其他任何可能覆蓋主文件的route.rb文件。 從終端,您可以運行find ./ -name routes.rb
,這將列出其他所有路由文件。 如果您安裝了任何Rails引擎,則尤其可能發生這種情況。
讓我知道這是怎么回事-如果您仍然遇到問題,可以將您的應用程序壓縮並通過電子郵件發送給我,我會看一下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.