title: Rails has_many through form with checkboxes and extra field in the join model
body: <p>I'm trying to solve a pretty common (as I thought) task.</p>
  
  <p>There're three models:</p>
  
  <pre><code>class Product &lt; ActiveRecord::Base  
    validates :name, presence: true
  
    has_many :categorizations
    has_many :categories, :through =&gt; :categorizations
  
    accepts_nested_attributes_for :categorizations
  end
  
  class Categorization &lt; ActiveRecord::Base
    belongs_to :product
    belongs_to :category
  
    validates :description, presence: true # note the additional field here
  end
  
  class Category &lt; ActiveRecord::Base
    validates :name, presence: true
  end
  </code></pre>
  
  <p>My problems begin when it comes to Product new/edit form.</p>
  
  <p>When creating a product I need to check  categories (via checkboxes) which it belongs to. I know it can be done by creating checkboxes with name like 'product[category_ids][]'. But I also need to enter a description for each of checked relations which will be stored in the join model (Categorization).</p>
  
  <p>I saw those beautiful Railscasts on complex forms, habtm checkboxes, etc. I've been searching StackOverflow hardly. But I haven't succeeded.</p>
  
  <p>I found one <a href="http://railsforum.com/viewtopic.php?id=42651">post</a> which describes almost exactly the same problem as mine. And the last answer makes some sense to me (looks like it is the right way to go). But it's not actually working well (i.e. if validation fails). I want categories to be displayed always in the same order (in new/edit forms; before/after validation) and checkboxes to stay where they were if validation fails, etc.</p>
  
  <p>Any thougts appreciated.
  I'm new to Rails (switching from CakePHP) so please be patient and write as detailed as possible. Please point me in the right way!</p>
  
  <p>Thank you. : )</p>