I have a system table and a table category, a system has many categories and a category has several systems, I wanted to use the has_and_belongs_to_many option of Rails (for being a simple interface and even to learn how to use this feature). But I'm doubtful in the following question, I have to create a migrate that manages a table that stores these relations or type Rails itself will take care of that by putting has_many_and_belong_to: systems and has_many_and_belong_to: Categories?
Has anyone used it, or do you have any suggestions / tips on how to do it?
System controller method
def sistem_params
params.require(:sistem).permit(:description, :categories)
end
Model Systems
class Sistem < ActiveRecord::Base
has_and_belongs_to_many :categories
has_many :versions
end
template Category
class Category < ActiveRecord::Base
has_and_belongs_to_many :sistems
has_many :tests
end
Migration of the table linking the templates
class CategoriesAndSistems < ActiveRecord::Migration
def change
create_table :categories_sistems do |t|
t.references :category, :sistem
end
end
end