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} }

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