我的控制器中有以下内容:
if params[:option] == "1"
id = params[:id]
@resultsReceived = true
begin
@pwvav_ratings = Pwvav.find_by_id(id).recommendation.split(",")
#or
@pwbab_ratings = Pwbab.find_by_id(id).recommendation.split(",")
#or
@puvub_ratings = Puvub.find_by_id(id).recommendation.split(",")
#or
@tic_ratings = Tic.find_by_id(id).recommendation.split(",")
rescue
redirect_to "/view_api", :flash => { :notice => "Sorry, No records returned for #{id}." }
end
如果 find 不为零,我正在尝试将每个实例变量(@pwvav_ratings
,@pwbab_ratings
...)设置为 find,以便我可以在我的视图中调用它。我如何检查是否..或如果没有找到,请使用 Flash 通知进行救援。