0
與非ID養在這種情況下我用得到它通過URL作爲site.com/john的ActiveRecord :: RecordNotFound不是在Rails 3中
可能是因爲查詢的類型,當尋找的用戶名URL具有不存在的用戶名Rails不會重新調用RecordNotFound異常,因此不會呈現適當的404頁面。我所做的目前的修復就像這段代碼,但我想從Rails中獲得異常,而不是像這樣看起來很臭。
def show
@user = User.first(:conditions => ["lower(username) = ?", params[:username].downcase])
if @user
...
else
redirect_to '/404.html'
end
end
謝謝