リンク モデルの article_template を作成できます
rails generate model articles_template
記事とテンプレートへの参照付き
class CreateArticlesTemplates < ActiveRecord::Migration
def change
create_table :articles_templates do |t|
t.references :article
t.references :template
t.timestamps
end
end
end
次に、モデルの article_template で関連付けを設定します
class ArticlesTemplate < ActiveRecord::Base
belongs_to :article
belongs_to :template
end
class Article < ActiveRecord::Base
has_many :articles_templates
has_many :templates, :through => :articles_templates
end
class Template < ActiveRecord::Base
has_many :articles_templates
has_many :articles, :through => articles_templates
end
リンクモデルとテーブルにいくつかの追加機能を直接追加できるため、これはベストプラクティスです。(これについての詳細はこちら)