我剛開始使用Rails 3的,我不太明白如何去重新命名路線。Rails 3條中重命名路線
我想要什麼:
到路徑重命名爲users#show
控制器/動作對。因此,而不是URL爲www.example.com/users/show/1
的這純粹是www.example.com/1/home
在未來,我還希望能夠增加額外的路徑到年底如:
www.example.com/1/home/profile/
我如何用戶資源設置:
resources :users, :except => [:destroy] do
resources :favorites, :only => [:show, :update]
resources :profiles, :only => [:show, :update]
end
我試了一下:
match :home, :to => 'users#show'
發生了什麼事:
ActiveRecord::RecordNotFound in UsersController#show
Couldn't find User without an ID
是什麼在development.log文件:
Started GET "/home" for 127.0.0.1 at 2011-03-10 13:36:15 -0500
Processing by UsersController#show as HTML
[1m[35mUser Load (1.6ms)[0m SELECT "users".* FROM "users" WHERE ("users"."id" = 101) LIMIT 1
Completed in 192ms
ActiveRecord::RecordNotFound (Couldn't find User without an ID):
app/controllers/users_controller.rb:19:in `show'
什麼是在用戶控制器:
def show
@user = User.find(params[:id])
respond_to do |format|
format.html # show.html.haml
end
end
所以,很顯然它是存儲用戶ID,如在開發日誌爲101
,但不管是什麼原因,我還是收到此錯誤?
你可以提供任何幫助,不勝感激!
這給出了一個路由錯誤:'沒有路由匹配{:controller =>「users」,:action =>「show」}' – iwasrobbed 2011-03-10 19:25:15
它應該工作。你可以顯示你的'耙路線'嗎? – Voldy 2011-03-10 19:37:54
下面是相關的rake路由:https://gist.github.com/864769 – iwasrobbed 2011-03-10 19:43:28