NoMethodError in nil class Ruby on Rails

    This error will come if you are missing method or don't have any record related to the path request so you need to handle this error simple add bang (!) in controller where you are getting data
    def request
        @request = Request.find_by_request_id!(params[:id])
        respond_to do |format|
           format.html {render :layout => "landing", :template => "requests/newrequest"}
           format.json { render :json => {:request => @request} }
        end
    end

    # ! rescue and  redirect to 404 page if no record exists for params[:id]
    5
    Average: 5 (1 vote)