title: How to use polymorphic_path in lib/module in Rails 4
body: <p>I want to call <a href="http://api.rubyonrails.org/classes/ActionDispatch/Routing/PolymorphicRoutes.html#method-i-polymorphic_path" rel="nofollow noreferrer">polymorphic_path</a> in a helper module located at <code>lib/my_module.rb</code>.</p>
  
  <p>I tried the following from <a href="https://stackoverflow.com/questions/27003252/how-can-i-access-polymorphic-path-inside-a-model-in-rails-4">this answer</a>, which works in a model, but not in my module:</p>
  
  <pre><code>module MyModule
    include ActionDispatch::Routing::PolymorphicRoutes
    include Rails.application.routes.url_helpers
  
    def link(model)
      polymorphic_path(model)
    end
  end
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>undefined method `polymorphic_path' for MyModule:Module
  </code></pre>
  
  <p>Btw, I load my module through <code>config.autoload_paths += %W(#{config.root}/lib)</code> in <code>config/application.rb</code>.</p>