title: Rails 3: Check for routing error in rails code
body: <p>I have a lot of courses in my website. I have a "go to course" form. When user inputs a valid course name, I successfully redirect that user to that course page.</p>
  
  <pre><code> def courses
      @title = "Courses"
      @path  = "#{root_path}"+"course/" + "#{params[:course]}"
      if @path == "/course/"
          @title = "Courses"
          render 'courses'
      else 
          redirect_to @path
      end
  end
  </code></pre>
  
  <p>This works for all valid inputs that is if the route exists. I want to take care of the error case when the user inputs invalid course name which would cause an invalid route. I want to check for routing error in the code and let the user know with an error message. Is this possible?"</p>