I have two models User and Category.
class User < ActiveRecord::Base
has_and_belongs_to_many :categories
accepts_nested_attributes_for :categories
end
similarly
class Category < ActiveRecord::Base
has_and_belongs_to_many :users
end
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?
And one more thing is i have to add an attribute type which refers that category type. for example
user1 ----> category1, category2
user2 ----> category2
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.
has_and_belongs_to_many :users
notcategories
, right? Also, what you want to do with thistype
. I don't get it.... – Baresark