How should we handle requests for invalid objects which do not exist in database, ActiveRecord::RecordNotFound error ? I am writing begin-rescue as follows: def show begin @phone = Phone.find(params[:id]) rescue ActiveRecord::RecordNotFound flash[:notice] = NONEXIST_OBJECT redirect_to :controller => :phone, :action => :index else respond_to do |format| format.html format.xml {render :xml => @agenda.to_xml} end end end
Instead of repeating this for show, edit, and delete in every controller, I would like to put this into an application_controller. How do I pass current controller name to the application controller? The controller and model names are matching, so I would generate a class name from controller name, then do a begin-find-rescue stuff.
Also, does this belong to controller? My first thought was to handle this in model, as it is related to ActiveRecord. Any thoughts on this ?
Please help me with putting it into app_con anyway.