title: Ruby on Rails has_and_belongs_to_many uninitialized constant
body: <p>I'm building a site on Refinery CMS, and have generated two extensions: one for <strong>Brands</strong>, and another for <strong>Bicycle Types</strong> (it's a site for a bike shop).</p>
  
  <p>Now, what I want to do is have the Brands extension handle the creation of brand pages, which will be pulled into a brand index. On this page, I want to be able to filter by Bicycle Type, which is where the second extension comes in. Through the Bicycle Type extension, you can create a bicycle type, which I want to associate to a Brand. A Brand can have multiple Bicycle Types, and vice versa.</p>
  
  <p>So, I edited the Brands model to add <code>has_and_belongs_to_many :bicycle_types</code>, and the Bicycle Types model to include <code>has_and_belongs_to_many :brands</code> and <code>accepts_nested_attributes_for :brands</code>. I wrote a migration to create a join table, and everything was going well so far.</p>
  
  <p>I then went to modify the form for the Brands extension, and got my checkboxes displaying correctly and seemingly generating the right code. However, the problem occurs when I come to submit the form - I get <code>NameError in Refinery::Brands::Admin::BrandsController#update</code> and <code>uninitialized constant Refinery::Brands::Brand::BicycleType</code>.</p>
  
  <p>The parameters I get look like the bicycle type IDs are being passed through correctly:</p>
  
  <pre><code>{"utf8"=&gt;"✓",
   "_method"=&gt;"put",
   "authenticity_token"=&gt;"3193ZMPXkmHdgZThXwAurD6xF2eZ533Tb71pAi7Jxbs=",
   "switch_locale"=&gt;"en",
   "brand"=&gt;{"title"=&gt;"Cannondale",
   "teaser"=&gt;"",
   "splash"=&gt;"",
   "details"=&gt;"",
   "introduction"=&gt;"",
   "blockquote"=&gt;"",
   "bicycle_type_ids"=&gt;["1",
   "2"],
   "logo_id"=&gt;"",
   "teaser_image_id"=&gt;"",
   "splash_image_id"=&gt;""},
   "id"=&gt;"2",
   "locale"=&gt;:en}
  </code></pre>
  
  <p>I've been trying to figure this out and just keep hitting the same brick wall, so any help would be greatly appreciated!</p>
  
  <p>Here's my code. Let me know if anything else would help.</p>
  
  <p><strong>Brands Controller</strong></p>
  
  <pre><code>module Refinery
    module Brands
      module Admin
        class BrandsController &lt; ::Refinery::AdminController
  
          crudify :'refinery/brands/brand',
                  :xhr_paging =&gt; true
  
        end
      end
    end
  end
  </code></pre>
  
  <p><strong>Brands Model</strong></p>
  
  <pre><code>module Refinery
    module Brands
      class Brand &lt; Refinery::Core::BaseModel
        self.table_name = 'refinery_brands'
  
        attr_accessible :title, :teaser, :splash, :details, :introduction, :blockquote, :logo_id, :teaser_image_id, :splash_image_id, :position, :bicycle_type_ids
  
        translates :title, :teaser, :splash, :details, :introduction, :blockquote
  
        class Translation
          attr_accessible :locale
        end
  
        validates :title, :presence =&gt; true, :uniqueness =&gt; true
  
        belongs_to :logo, :class_name =&gt; '::Refinery::Image'
  
        belongs_to :teaser_image, :class_name =&gt; '::Refinery::Image'
  
        belongs_to :splash_image, :class_name =&gt; '::Refinery::Image'
  
        has_and_belongs_to_many :bicycle_types
      end
    end
  end
  </code></pre>
  
  <p><strong>Bicycle Types Model</strong></p>
  
  <pre><code>module Refinery
    module BicycleTypes
      class BicycleType &lt; Refinery::Core::BaseModel
        self.table_name = 'refinery_bicycle_types'
  
        attr_accessible :title, :position
  
        translates :title
  
        class Translation
          attr_accessible :locale
        end
  
        validates :title, :presence =&gt; true, :uniqueness =&gt; true
  
        has_and_belongs_to_many :brands
        accepts_nested_attributes_for :brands
      end
    end
  end
  </code></pre>
  
  <p><strong>Migration</strong></p>
  
  <pre><code>class AddRefineryBicycleTypesBrands &lt; ActiveRecord::Migration
    def change
      create_table :bicycle_types_brands, :id =&gt; false do |t|
        t.references :bicycle_type
        t.references :brand
      end
      add_index :bicycle_types_brands, [:bicycle_type_id, :brand_id], :unique =&gt; true
    end
  end
  </code></pre>
  
  <p><strong>Form Partial (at least the part where I'm building my checkboxes)</strong></p>
  
  <pre><code>&lt;div class="field"&gt;
    &lt;%= f.label :bicycle_types %&gt;
      &lt;% Refinery::BicycleTypes::BicycleType.order(:title).each do |bicycle_type| %&gt;
        &lt;label class="checkbox"&gt;
          &lt;%= check_box_tag "#{f.object_name}[bicycle_type_ids][]", bicycle_type.id, f.object.bicycle_types %&gt;
        &lt;%= bicycle_type.title %&gt;
      &lt;/label&gt;
    &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>If the rest of the partial would be useful, or anything else for that matter, please let me know. Any help would be greatly appreciated!</p>