title: Join Table ActiveRecord Invalid Record on Save (Rails 5)
body: <p>I have a join table between <code>freebies</code> and <code>subcategories</code> that is acting up.</p>
  <p>(I have an existing join table between <code>freebies</code> and <code>categories</code> that is absolutely fine, after which the subcategories is modeled, but I can't tell where the difference is that makes it act up.)</p>
  <p>Here's my <code>freebie.rb</code> model:</p>
  <pre><code>class Freebie &lt; ApplicationRecord
    has_many :blogs
    has_one_attached :image
    has_one_attached :sample_image
    has_one_attached :t1_image
    has_one_attached :fb_share_image
    has_many_attached :pin_image
  
    extend FriendlyId
    friendly_id :name, use: :slugged
  
    has_many :categorization_freebies
    has_many :categories, through: :categorization_freebies
  
    has_many :subcategorization_freebies
    has_many :subcategories, through: :subcategorization_freebies
  end
  </code></pre>
  <p>And my <code>subcategory.rb</code> model:</p>
  <pre><code>class Subcategory &lt; ApplicationRecord
    belongs_to :category
  
    has_many :subcategorization_freebies
    has_many :freebies, through: :subcategorization_freebies
  end
  </code></pre>
  <p>And finally the <code>subcategorization_freebie.rb</code> join table:</p>
  <pre><code>class SubcategorizationFreebie &lt; ApplicationRecord
    belongs_to :subcategory
    belongs_to :freebie
  end
  </code></pre>
  <p>So here's the form that's used to create the new freebie (where the error is appearing):</p>
  <pre><code>&lt;%= simple_form_for(@freebie) do |f| %&gt;
    ...
        &lt;div class=&quot;form-group form-check jsItUp&quot;&gt;
        &lt;h5&gt;Categories&lt;/h5&gt;
        &lt;%= f.collection_check_boxes(:category_ids, Category.all, :id, :name ) %&gt;
      &lt;/div&gt;
  
      &lt;div class=&quot;form-group form-check jsItUp&quot;&gt;
        &lt;h5&gt;Subcategories&lt;/h5&gt;
        &lt;%= f.collection_check_boxes(:subcategory_ids, Subcategory.all, :id, :name ) %&gt;
      &lt;/div&gt;
   ...
  &lt;% end %&gt;
  </code></pre>
  <p>The permissions in the <code>freebies_controller.rb</code> controller are like this:</p>
  <pre><code>def freebie_params
    params.require(:freebie).permit(
      :name,
      :category,
      :short_description,
      :convertkit_url,
      :active,
      :thrivelink,
      
      :image,
      :sample_image,
      :t1_image,
      :fb_share_image,
      :pin_image,
  
      :top_question,
      :main_heading,
      :main_subheading,
      :t1_short,
      :t1_name,
      :t1_title,
      :t1_long,
      :wyg1,
      :wyg2,
      :wyg3,
      :outcome,
      :outcome_2,
  
      :ml_id,
      :ml_submit_code,
      :after_download_url,
      :ml_img_track_url,
  
      category_ids: [],
      subcategory_ids: []
    )
  end
  </code></pre>
  <p>When the form is submitted it gives an error that says <code>Validation failed: Subcategories is invalid</code>.</p>
  <p>The server log when this occurs goes like this:</p>
  <pre><code>app/controllers/freebies_controller.rb:33
     (0.2ms)  ROLLBACK
    ↳ app/controllers/freebies_controller.rb:33
  Completed 422 Unprocessable Entity in 15ms (ActiveRecord: 5.3ms)
  
  
  ActiveRecord::RecordInvalid - Validation failed: Subcategories is invalid:
    app/controllers/freebies_controller.rb:33:in `block in create'
    app/controllers/freebies_controller.rb:32:in `create'
  </code></pre>
  <p>Can anyone see where I'm going wrong?  Most of the code was copied directly from the categories relationship...which works just fine.  Help!</p>