2012-08-15 53 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 

相关问题