0
我有一個導航系統爲任何鏈接設置提供永久鏈接。find_by_field在ActiveRecord中無法正常工作
當我運行通過腳本/控制檯行這是它返回:
>> Navigation.find_by_permalink("gems")
=> #<Navigation id: 10, text: "Gems", parent: nil, destination_controller: "pages", destination_action: "show", destination_id: "1", permalink: "gems", created_at: "2009-12-26 14:56:28", updated_at: "2009-12-26 14:56:28", previous: 9>
當我把我的應用程序,我得到這樣的:
ActiveRecord::RecordNotFound in NavigationsController#permalink
Couldn't find Navigation without an ID
我的請求「/永久/寶石「和相關的路線是:
map.permalink "permalink/:permalink", :controller => 'navigations', :action => 'permalink'
處理該請求的控制器代碼是:
def permalink
@nav=Navigation.find_by_permalink(params[:permalink])
redirect_to :controller => @nav.destination_controller, :action => @nav.destination_action, :id => @nav.destination_id
end
任何人都知道爲什麼會發生這種情況?
能否請您發表您的控制器代碼?也許參數值由於某種原因沒有得到適當的傳遞。 – Priyank
您是否在控制器中執行了「p」操作,並檢查params [:permalink]的值是否到來? – Priyank
我有問題重新獲取params [:permalink]的值,我註釋掉了當前的代碼並添加了「flash [:notice] = params [:permalink]」並重定向到了根url,但我仍然遇到同樣的問題 – Arcath