title: Display just the subcategories of the chosen category
body: <p>This is the code I currently have: </p>
  
  <pre><code>&lt;%= f.collection_select :category_id, Category.all, :id, :name, {prompt: "Choose a category"} %&gt;
  &lt;%= f.collection_select :subcategory_id, Subcategory.all, :id, :name, {prompt: "Choose a subcategory"} %&gt;
  </code></pre>
  
  <p>All it does is to display in one dropdown <strong>all</strong> the categories and in another <strong>all</strong> the subcategories.
  like this <img src="https://i.stack.imgur.com/hkd1a.png" alt="the drop downs."></p>
  
  <blockquote>
    <p><strong>Question:</strong> How to make just the specific subcategories appear depending on the chosen main category. With the code above, it shows all the categories and all subcategories.</p>
  </blockquote>
  
  <p>Everything is linked in the model, the has_many, and belongs_to...and category_id and subcategory_id..everything is working properly, I just don't know how to show the specific subcategories within chosen category.</p>
  
  <p>My attempt:</p>
  
  <pre><code>  &lt;% if (Category.where(:name=&gt;"Intro")) do |d| %&gt;
      &lt;% d.subcategories.each do |subcategory| %&gt;
        &lt;%= link_to subcategory.name, gigs_path(subcategory: subcategory.name) %&gt;
      &lt;% end %&gt;
    &lt;% end %&gt;
  </code></pre>
  
  <p>This code gives an error. I though to say if, for example, the user picks the category called "Intro" than list all the "Intro subcategories". But it didn't work out - my code is obviously wrong.</p>
  
  <p><em>Thank you.</em></p>