2012-08-15 68 views
0

剛開始使用databasedotcom寶石,現在卡住了。databasedotcom錯誤沒有找到記錄

當試圖找到憑身份證在Salesforce的記錄,如果ID /記錄不存在,它產生以下錯誤:

「提供的外部ID字段不存在或無法訪問:」

如果Id確實存在,我可以繼續使用我的頁面。

這裏是我的代碼:

def search 
@account = Account.find(params[:id]) 

if @account.Id 
    redirect_to new_user_registration_path(:id => @account.Id) 
elsif params[:id].to_s.present? and @account.nil? 
    flash[:alert] = "Couldn't find that one. Please check and re-submit your number." 
    redirect_to search_path 
end 

我怎樣才能解決這個?

謝謝。

回答

0

將代碼更改爲以下版本,現在工作正常 - 謝謝Danny Burkes。它捕獲異常並相應地路由。

def search 
begin 
@account = Account.find(params[:id]) 

if @account.Id 
    redirect_to new_user_registration_path(:id => @account.Id) 
end 
rescue Exception => e 
    flash[:alert] = "Couldn't find that one. Please check and re-submit your number." 
    redirect_to search_path 
end 

相關問題