title: Rails 4 Include Rails.application.routes.url_helper undefined method routes for nil:NilClass
body: <p>I am working on a Ruby gem (aimed at Rails 4) and I want to be able to use the url helpers in it.  So I've tried adding <code>include Rails.application.routes.url_helpers</code>, but it results in "undefined method 'routes' for nil:NilClass (NoMethodError)."</p>
  
  <p>I am unsure as to why it does this as I've tested in the console and when I included it there it does just fine.</p>
  
  <p>The class and module is simple just:</p>
  
  <pre><code> module DynamicMenu
    class Base
      include Rails.application.routes.url_helpers
      def get_menu_links
        @links
      end
      private
  
      def define_menu_links(args)
       @links = args
      end
    end
  end
  </code></pre>
  
  <p>Any ideas on how to fix this?  I've tried including diffent modules, such as ActionView::Helpers, but that doesn't appear to work either.</p>