2011-04-10 109 views
0

感嘆 - Rails 3路由仍然讓我感到困惑。這裏的route.rb線 -Rails 3 URL Helper無法正常工作?

match "/ghosts/:pid" => 'ghosts#update', :constraints => { :method => 'PUT' } 

這裏的視圖代碼:

<%= form_tag (admin_ghosts_path(@pid), :method => :put) do |f| %> 

這裏就是獲取呈現

<form accept-charset="UTF-8" action="/admin/ghosts.jbdlljhhxz" method="post"> 

但什麼應該被渲染爲

<form accept-charset="UTF-8" action="/admin/ghosts/jbdlljhhxz" method="post"> 

對此提出建議?此外,有沒有辦法有標準的路線:

resources :ghost, :only => [:index, :show, :update] do 
    get :index 
    get :show 
    put :update 
end 

使用「:PID」,而不是「:ID」而不做比賽就像我上面?

回答

1

我認爲你需要admin_ghost_path(@pid)而不是admin_ghosts_path(@pid)。由於您正在調用沒有任何常規參數的URL助手,因此您傳遞的參數將被視爲協議參數值。

要查看路由的正確幫助程序名稱,請從命令提示符處運行rake routes

+0

你得到支票 - 它最終成爲我必須從鬼魂變爲鬼魂,並從使用匹配格式,使用標準的'會員做'格式 - 順便說一句,任何想法如何堅持價值在params [:pid]而不是params [:id]? – aronchick 2011-04-11 02:30:56