I have the following in my controller:
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
I am trying to set each of those instance variables (@pwvav_ratings
,@pwbab_ratings
...) to the find if the find is not nil, so that I can call it in my view. How do I check if..or and if nothing is found, rescue with the flash notice.