title: How can i use accepts nested attributes with the HABTM?
body: <p>I have two models User and Category. </p>
  
  <pre><code>    class User &lt; ActiveRecord::Base
          has_and_belongs_to_many :categories
          accepts_nested_attributes_for :categories
      end
  </code></pre>
  
  <p>similarly</p>
  
  <pre><code>    class Category &lt; ActiveRecord::Base
          has_and_belongs_to_many :users
      end
  </code></pre>
  
  <p>i have a requirement where i have to add the categories to the categories table and add the reference so that i can get the categories related to user but if another user enters the same category then i have to make use of the id instead of creating new one. How can i do it?</p>
  
  <p>And one more thing is i have to add an attribute type which refers that category type. for example</p>
  
  <pre><code>user1 ----&gt; category1, category2
  user2 ----&gt; category2
  </code></pre>
  
  <p>here user1 and user2 has category2 but the type in category2 may differ.So how can i maintain this? please help me. I am ready to answer your question.</p>