title: Rails: Determine if an object has a named route
body: <p>In a Rails 3.1 app, I want to list a bunch of objects of variable class (from a polymorphic table) which I don't know in advance. For those that are resources with a named route, I'd like to use that route in a <code>link_to</code> call. Naive approach without checking if such a route exists (excuse the HAML):</p>
  <pre><code>%ul
  - @objects.each do |object|
    %li= link_to object, url_for(object)
  </code></pre>
  <p>This will raise a <code>undefined method 'foo_path'</code> error if the object is an instance of class <code>Foo</code> which does not have a named route (for example because it's not defined as a resource). Is there an easy way (such as a simple method call) to determine the existence of a named route for an object or class?</p>
  <p>What I would like to get is something like this:</p>
  <pre><code>%ul
  - @objects.each do |object|
    %li= link_to_if object.has_route?, object, url_for(object)
  </code></pre>