title: How to setup nested routing for a self referencing controller in Rails 4
body: <p>I have a Categories controller setup as a self referencing controller to give me the ability to create a series of sub categories. However, I am completely lost on how I would go about setting up routing in my application so I could have urls such as <a href="http://www.example.com/category/subcategory/product/" rel="nofollow">http://www.example.com/category/subcategory/product/</a></p>
  
  <p>I currently have my categories routing set up as such </p>
  
  <pre><code>resources :categories, except: :index, :path =&gt; '/'
  </code></pre>
  
  <p>and my model set up as</p>
  
  <pre><code>class Category &lt; ActiveRecord::Base
    has_many :subcategories, :class_name =&gt; "Category", :foreign_key =&gt; "parent_id", :dependent =&gt; :destroy
    belongs_to :parent_category, :class_name =&gt; "Category", :foreign_key=&gt;"parent_id"
  end
  </code></pre>
  
  <p>However, I am completely stumped as to where I would start with such a task after reading through the Rails guide to routing and searching elsewhere for a solution. Any help would be much appreciated!</p>