2013-02-24 53 views
0

我的投票鏈接通常工作,除非鏈接通過ajax部分呈現。當通過JavaScript部分渲染時,我得到一個路由錯誤,在螢火蟲中可見並且沒有錯誤。僅當使用ajax時導軌路由錯誤

沒有螢火蟲我知道有一個錯誤,因爲當我嘗試添加一個新的製造商時沒有添加製造商。如果我手動刷新頁面,則鏈接和新制造商出席並投票。

所以基本上使用ajax打破投票鏈接。

耙路線:

vote_car_manufacturer POST /cars/:car_id/manufacturers/:id/vote(.:format)    manufacturers#vote 

觀點:

<%= link_to '+', vote_car_manufacturer _path(car_id: @car.id, manufacturer_id: manufacturer.id, type: "up"), method: "post" %> 

螢火蟲:

No route matches {:action=>"vote", :controller=>"manufacturers", :car_id=>1, :manufacturer_id=>29, :type=>"up"} 

使用Ajax時我一定要執行不同的投票鏈接?

UPDATE

得到通過試驗和錯誤時半的工作。更改:

<%= link_to '+', vote_car_manufacturer _path(car_id: @car.id, manufacturer_id: manufacturer.id, type: "up"), method: "post" %> 

到:

<%= link_to '+', vote_car_manufacturer _path(@car.id, manufacturer.id, "up"), :method => :post %> 

現在它說,沒有一個ID,所以我還在調試中無法找到生產廠家。

回答

0

的解決方案是非常微不足道的。首先運行耙路線,並確保您以正確的格式提供路線請求的參數。

在我的情況的參數應該是vote_car_manufacturer _path(@ car.id,ID:製造商,型號: 「向上」)

+1

我很高興你解決了你的問題。不要忘記給自己勾選標記。 – 2014-01-23 11:06:19