title: Active Admin with join table relation
body: <p>I am configuring Active Admin. Everything is running apart from a join table, which connects the magazine resource with the keyword resource. One magazine is defined by multiple keywords and a keyword can define multiple magazines.</p>
  
  <p>I have two models:</p>
  
  <pre><code>### models/magazine.rb
  
  class Magazine &lt; ActiveRecord::Base
      attr_accessible :colour, :cover_alt, :description, :number, :short, :title_id
  
      has_and_belongs_to_many :keywords, :join_table =&gt; "magazines_keywords" 
      belongs_to :title, :class_name =&gt; "Keyword", :foreign_key =&gt; "title_id"
  end
  
  
  ### models/keywords.rb
  
  class Keyword &lt; ActiveRecord::Base
    attr_accessible :word, :description
  
    has_and_belongs_to_many :magazines, :join_table =&gt; "magazines_keywords"
  end
  </code></pre>
  
  <p>And a join table:</p>
  
  <pre><code>### models/magazines_keyword.rb
  class MagazinesKeyword &lt; ActiveRecord::Base
    attr_accessible :magazine_id, :keyword_id
  
    belongs_to :magazine
    belongs_to :keyword
  end
  </code></pre>
  
  <p>This setting works for the views of my rails app, and I have the index and show section of my AA magazine resource working, but the form (for new and edit) does not work:</p>
  
  <pre><code>ActiveAdmin.register Magazine do
      menu :priority =&gt; 1
  
      form do |f|
          f.semantic_errors *f.object.errors.keys
          f.inputs "Magazine Details" do
              f.input :title_id, :label =&gt; 'Title', :as =&gt; :select, :collection =&gt; Keyword.all.map{ |u| ["#{u.word.capitalize}", u.id] }
              f.inputs :magazines_keywords do
                  f.has_many : magazines_keywords do |s|
                      s.input :keyword, :as =&gt; :select, :multiple =&gt; true, :collection =&gt; MagazinesKeyword.all.map { |u| ["#{u.keyword.word.capitalize}", u.id] }
                  end
              end
          end
          f.actions
      end
  
      show do
          panel "Magazine Details" do
              attributes_table_for magazine do
                  row "Keywords", :keyword do |m|
                      m.keywords.map { |d| d.word }.join(", ").html_safe
                  end
              end
          end
          active_admin_comments
      end
  end
  </code></pre>
  
  <p>When running the app i get <code>NoMethodError in Admin/magazines#edit</code></p>
  
  <p>Where <code>/active_admin/resource/edit.html.arb line #1</code> raises <code>undefined method 'klass' for nil:NilClass</code></p>
  
  <p>I can display all the keywords in the form section with:</p>
  
  <pre><code>f.input :magazines_keywords, :as =&gt; :check_boxes, :multiple =&gt; true, :collection =&gt; MagazinesKeyword.all.map{ |u| ["#{u.keyword.word.capitalize}", u.id] }
  </code></pre>
  
  <p>But when I try to write them it does not work. Editing the values does not work either.</p>
  
  <p>Where am I missing something? How can I get this working?</p>
  
  <p>****UPDATE****</p>
  
  <p>After some work I got the following solution:</p>
  
  <pre><code>form do |f|
      f.semantic_errors *f.object.errors.keys
      f.inputs "Saft Details" do
          f.input :title_id, :label =&gt; 'Title', :as =&gt; :select, :collection =&gt; Keyword.all.map{ |u| ["#{u.word.capitalize}", u.id] }
          f.input :keywords, :as =&gt; :check_boxes, :input_html =&gt; {:multiple =&gt; true}
      end
      f.actions
  end
  </code></pre>
  
  <p>And as suggested:</p>
  
  <pre><code>f.input :keywords, :as =&gt; :check_boxes, :input_html =&gt; {:multiple =&gt; true} do
      f.has_many :keywords do |s|
          s.input :keyword, :collection =&gt; Keyword.all.map { |kw| ["#{kw.word.capitalize}", kw.id] }
          end
  end
  </code></pre>
  
  <p>With both solutions I am able to write a new Magazine entry and get the association written to the join table, unfortunately it displays <code>#&lt;Keyword:0x10c858858&gt;</code> in the form and not the word. What am I missing?</p>