我已經在我的Rails 4應用程序中成功使用friendly_id與多個模型。我以前有兩個我決定合併的模型(終端和位置)。終端顯示操作之前與friendly_id一起工作,在那裏我可以訪問/ terminals/albany並使終端獲得'albany'slu'。故障排除friendly_id w/Rails 4:按照預期在Rails控制檯中工作,從控制器中獲取RecordNotFound錯誤
我已經經歷了大量的重構來凝聚到只是地點,並在最後一塊(固定視圖)。一路上,我一直在Rails控制檯中測試事情,並使用rspec,事情似乎按預期工作。還有其他模型仍然按預期工作。
如今,我工作地點在新節目頁面上,我得到試圖訪問/位置時,下面的錯誤/奧爾巴尼:
ActiveRecord::RecordNotFound in LocationsController#show
Couldn't find Location with id=albany
然而,當我訪問/位置/ 5 ,它成功加載了該記錄。它也可以在Rails的控制檯:
Location.find(5) # returns the correct location object
Location.find(5).slug # returns 'albany'
Location.friendly.find('albany') # returns the correct location object
當我看到在Rails的DBCONSOLE生成的蛞蝓,他們看起來都像他們正確生成,並沒有重複。
這裏是我的模型:
Class Location < ActiveRecord::Base
extend FriendlyId
friendly_id :slug_candidates, use: [:slugged, :history]
def slug_candidates
[
:name,
[:name, :zip],
[:name, :zip, :location_type],
]
end
end
這是我的節目在我的控制器動作:
def show
@locations = Location.friendly.find(params[:id])
end
我難倒!任何提示?
只是pinging - 任何人在那裏? – Shane
我也被困在這 - 你能弄清楚什麼? – vikhyat
你們誰都知道了?獲得同樣的問題。 – daveomcd