刚开始使用databasedotcom gem并且现在卡住了。
尝试按Id在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 :(得分: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
端