title: Check to see whether a route exist or not in Rails 3
body: <p>Can we check/test for existence of a route in Rails?</p>
  
  <p>For example, I want to show a navigation bar that should show all of it's menu URL, regardless the URL exist or not. (to differ between the two, the broken url would use a different styling). </p>
  
  <p>The code to show each menu would look like this:</p>
  
  <pre><code>%li= link_to_unless_current menu.name, :controller =&gt; menu.controller, :action =&gt; menu.action
  </code></pre>
  
  <p>However, Rails would complaint and throw an exception, if the supplied controller and action route doesn't exist. </p>
  
  <p>Does Rails have a function to check before I do the aforementioned code?. Perhaps, something that looks like this:</p>
  
  <pre><code>-if some_function_to_check_route_existence?(:controller =&gt; menu.controller, :action =&gt; menu.action)
  </code></pre>
  
  <p><strong>EDITED:</strong></p>
  
  <p>Rather than using "controller" and "action" columns for the menu, i use a "url" column instead. Now, I can do something like this:</p>
  
  <pre><code>- if Menu.root
        - for menu in Menu.root.self_and_descendants
          - if menu.url
            %li= link_to_unless_current menu.name, menu.url
          - else
            %li= menu.name
  </code></pre>
  
  <p>I can also use rails function to determine existence of a route, such as:</p>
  
  <pre><code>Rails.application.routes.recognize_path
  </code></pre>