title: ActiveRecord::AssociationTypeMismatch in Controller#create Error in my Project
body: <p>Can I get some assistance with my code which is throwing an <code>ActiveRecord::AssociationTypeMistach</code> in my JobsController#create. </p>
  
  <pre><code>ActiveRecord::AssociationTypeMismatch (JobCategory(#70843392) expected, got "At Home" which is an instance of String(#20478408)):    
  app/controllers/jobs_controller.rb:46:in `create'
  </code></pre>
  
  <p>I am posting data through the form </p>
  
  <pre><code>&lt;%= form_for @job do |f| %&gt;
    &lt;div class="row"&gt;
      &lt;div class="col-md-4 select"&gt;
        &lt;div class="form-group"&gt;
          &lt;label&gt;Job Category&lt;/label&gt;
          &lt;%= f.collection_select :job_category, JobCategory.order(:job_category),
            :job_category, :job_category, include_blank: false, id: "job_category",
            prompt: "Select...", class: "form-control" %&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="col-md-4 select"&gt;
        &lt;div class="form-group"&gt;
          &lt;label&gt;Job Type&lt;/label&gt;
          &lt;%= f.grouped_collection_select :job_type, JobCategory.order(:job_category),
            :job_types, :job_category, :job_type_id, :job_type, id: "job_type",
            prompt: "Select...", class: "form-control"    %&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="col-md-4 select"&gt;
        &lt;div class="form-group"&gt;
          &lt;label&gt;Frequency&lt;/label&gt;
          &lt;%= f.select :recurrence, [["One Off", "One Off"], ["Daily", "Daily"],
            ["Weekly", "Weekly"], ["Bi-Monthly", "Bi-Monthly"],
            ["Once-Monthly", "Once-Monthly"]],
            id: "recurrence", prompt: "Select...", class: "form-control" %&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
    &lt;div&gt;&lt;%= f.submit "Post My Job", class: "btn btn-normal" %&gt;&lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Schema for Job Model</p>
  
  <pre><code>  create_table "jobs", primary_key: "job_id", force: :cascade do |t|
      t.string "job_title"
      t.text "job_description"
      t.text "key_instructions"
      t.integer "budget"
      t.datetime "booking_date"
      t.string "recurrence"
      t.boolean "is_flexible"
      t.string "address"
      t.boolean "active"
      t.integer "user_id"
      t.datetime "date_posted"
      t.datetime "date_ending"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
      t.boolean "featured"
      t.boolean "premium"
      t.integer "job_category_id"
      t.integer "job_type_id"
      t.string "job_category"
      t.string "job_type"
      t.index ["job_category_id"], name: "index_jobs_on_job_category_id"
      t.index ["job_type_id"], name: "index_jobs_on_job_type_id"
      t.index ["user_id"], name: "index_jobs_on_user_id"
    end
  </code></pre>
  
  <p>I am posting the data from my form into my job.rb model but in the process using job_category.rb models and job_type.rb associations for additional info. The three models are related as follows</p>
  
  <pre><code>class Job &lt; ApplicationRecord
    belongs_to :user
    belongs_to :job_category
    belongs_to :job_type
    has_many_attached :images
  
    validates :job_category, presence: true
    validates :job_type, presence: true
    validates :recurrence, presence: true    
  end
  
  class JobType &lt; ApplicationRecord
    has_many :job_categories
    has_many :jobs
  
    #attr_accessible :job_type
    #validates :job_type, :presence =&gt; true
  end
  
  class JobCategory &lt; ApplicationRecord
    has_many :job_types
    has_many :jobs
  
    #attr_accessible :job_category
    #validates :job_category, :presence =&gt; true    
  end
  </code></pre>
  
  <p>Any tips on where I am going wrong would be useful. Thanks</p>