I am trying to redirect if the record is not found.
The page is not redirect and I get the error record not found.
My controller:
def index
@link = Link.find(params[:id])
respond_to do |format|
if @link.blank?
format.html { redirect_to(root_url, :notice => 'Record not found') }
else
format.html { render :action => "index" }
end
end
end
What I’ve been doing is putting this at the end of the method:
Even better, put it as an around_filter for your controller: