In your case,it should be categories has_many posts
and post belongs to category
Class Category < ActiveRecord::Base
has_many :posts, dependent: :destroy
end
Class Post < ActiveRecord::Base
belongs_to :category
end
By giving this,you should be having a category_id(Foreign key)
in your posts table.
So when you are creating a post,you can able to select categories through a collection_select
or select
.
Hope it helps!