title: Active Admin has_many through table not rendering in form - have tried everything
body: <p>Using Rails 3.2 and having a lot of trouble with Active Admin's has_many :through. The goal is to pull in the has_many :through subcategories through the contents model and create checkboxes for all of the subcategories. I've read the Active Admin documentation, searched other articles on stack, github, etc. Nothing is working. My only guess there could be something with the "form :html => { :enctype => "multipart/form-data" } do |f|" tag, which I need for PaperClip.</p>
  
  <p>*I've tried using accepts_nested_attributes and it doesn't work...</p>
  
  <p>There is a has_many :through table for subcategories and contents.
  Here is what it looks likes in the database:</p>
  
  <pre><code>create_table "contents", :force =&gt; true do |t|
    t.string   "title"
    t.text     "short_description"
    t.text     "long_description"
    t.datetime "published_date"
    t.datetime "edited_date"
    t.string   "read_length_time"
    t.string   "tag"
    t.integer  "author_id"
    t.integer  "contenttype_id"
    t.string   "collection"
    t.integer  "collection_id"
    t.string   "subcategory"
    t.integer  "subcategory_id"
    t.boolean  "published"
    t.datetime "created_at",               :null =&gt; false
    t.datetime "updated_at",               :null =&gt; false
    t.string   "image_file_name"
    t.string   "image_content_type"
    t.integer  "image_file_size"
    t.datetime "image_updated_at"
    t.string   "infographic_file_name"
    t.string   "infographic_content_type"
    t.integer  "infographic_file_size"
    t.datetime "infographic_updated_at"
    t.string   "video"
  end
  
  create_table "subcategories", :force =&gt; true do |t|
    t.string   "title"
    t.integer  "category_id"
    t.string   "content"
    t.integer  "content_id"
    t.datetime "created_at",  :null =&gt; false
    t.datetime "updated_at",  :null =&gt; false
  end
  
  create_table "subcats_contents", :id =&gt; false, :force =&gt; true do |t|
    t.integer "subcategory_id"
    t.integer "content_id"
  end
  
  add_index "subcats_contents", ["content_id"], :name =&gt; "index_subcats_contents_on_content_id"
  add_index "subcats_contents", ["subcategory_id", "content_id"], :name =&gt; "index_subcats_contents_on_subcategory_id_and_content_id"
  add_index "subcats_contents", ["subcategory_id"], :name =&gt; "index_subcats_contents_on_subcategory_id"
  </code></pre>
  
  <p>Here are the models:</p>
  
  <pre><code>class Content &lt; ActiveRecord::Base
    attr_accessible :author,
                    :edited_date,
                    :image,
                    :long_description,
                    :published_date,
                    :read_length_time,
                    :short_description,
                    :tag,
                    :title,
                    :type,
                    :collection_id,
                    :collection,
                    :collections_content,
                    :image,
                    :author_id,
                    :contenttype_id,
                    :subcategory,
                    :image_file_name,
                    :image_content_type,
                    :image_file_size,
                    :image_updated_at,
                    :subcats_contents,
                    :published,
                    :infographic_file_name,
                    :infographic_content_type,
                    :infographic_file_size,
                    :infographic_updated_at,
                    :infographic,
                    :video
  
    has_many :collections_contents
    has_many :collections, :through =&gt; :collections_contents
  
    has_many :subcats_contents
    has_many :subcategories, :through =&gt; :subcats_contents
  
    belongs_to :author
    belongs_to :contenttype
  
    validates_presence_of :title
    validates_presence_of :author_id
    validates_presence_of :published_date
    validates_presence_of :read_length_time
    validates_presence_of :contenttype
    validates_presence_of :tag
    validates :published, inclusion: [true, false]
  
    has_attached_file :image, :styles =&gt; { :medium =&gt; "500x800&gt;", :thumb =&gt;"500x500&gt;" }
    has_attached_file :infographic, :styles =&gt; { :medium =&gt; "1000x1000&gt;", :thumb =&gt;"300x300&gt;" }
  
    scope :published, where(:published =&gt; true )
    scope :unpublished, where(:published =&gt; false )
  
  
  end
  
  class Subcategory &lt; ActiveRecord::Base
    attr_accessible :category,
                    :category_id,
                    :content,
                    :content_id,
                    :title,
                    :subcats_contents
  
    has_many :subcats_contents
    has_many :contents, :through =&gt; :subcats_contents
  
    belongs_to :category
  
  end
  
  class SubcatsContent &lt; ActiveRecord::Base
    attr_accessible :subcategory,
                    :content
  
    belongs_to :subcategory
    belongs_to :content
  
  end
  </code></pre>
  
  <p>Then in my active admin form I've tried everything... here is the current state:</p>
  
  <pre><code>ActiveAdmin.register Content do
    scope :all, :default =&gt; true
    scope :published
    scope :unpublished
  
    filter :author
    filter :contenttype, :label =&gt; "Content Type"
    filter :title
    filter :short_description, :label =&gt; "Summary"
    filter :long_description, :label =&gt; "Content Body"
    filter :published_date
    filter :tag, :label =&gt; "Tags"
    filter :subcategory, :label =&gt; "Subcategories"
    filter :image_file_name
  
    index do
      column :published
      column :title
      column :author
      column :published_date
      column :short_description, :label =&gt; "Summary"
      column :long_description, :label =&gt; "Content Body"
      column :image_file_name, :label =&gt; "Image"
      column :tag
      actions
    end
  
    form :html =&gt; { :enctype =&gt; "multipart/form-data" } do |f|
       f.inputs "Contents" do
        f.input :published, :as =&gt; :select
        f.input :title
        f.input :short_description, :label =&gt; "Summary"
        f.input :long_description, :label =&gt; "Content Body"
        f.input :read_length_time, :label =&gt; "Estimated Read Length Time"
        f.input :author
        f.input :contenttype, :label =&gt; "Type of Content"
        f.input :image, :as =&gt; :file
        f.input :infographic, :as =&gt; :file
        f.input :video, :label =&gt; "Video * Please add the embed code (not just the URL)"
        f.input :tag, :label =&gt; "Tags"
        f.input :published_date
        f.input :subcategory, :as =&gt; :select, :input_html =&gt; { :multiple =&gt; true }
      end
  
      f.has_many :subcatscontents do |app_f|
        app_f.inputs "Subcats Contents" do
        app_f.input :subcategories 
       end
      end
  
    f.buttons
   end
  end
  </code></pre>
  
  <p>Here is the error I get in Active Admin when I go to create a new content:
  undefined method `klass' for nil:NilClass</p>
  
  <p>Thanks for any help and I apologize in advance if something isn't semantically up to par - new to this site.</p>