あなたが行うことのできることの1つは、ページにテキストを表す「コンテンツ」または「コピー」というモデルをデータベースに追加することです。次に、多形関連を使用してコンテンツ/コピーを実際のモデルにリンクすることができます。たとえば、製品のリストを含むページがある場合、データベースにProductモデルがある可能性があります。製品ページをレンダリングする際に、ユーザーがこの製品のために入力したすべてのテキストを取得するためにproduct.contents @呼び出すことができ、このシナリオでは
class Content < ActiveRecord::Base
belongs_to :contentable, :polymorphic => true # excuse my lame naming here
# this model would need two fields to make it polymorphic:
# contentable_id <-- Integer representing the record that owns it
# contentable_type <-- String representing the kind of model (Class) that owns it
# An example would look like:
# contentable_id: 4 <--- Product ID 4 in your products table
# contentable_type: Product <--- Tells the rails app which model owns this record
# You'd also want a text field in this model where you store the page text that your
# users enter.
end
class Product < ActiveRecord::Base
has_many :contents, :as => :contentable # again forgive my naming
end
:あなたはこのような何かを行うことができます。このように2つの別々のモデルを使用したくない場合は、Productモデル自体にテキストフィールドを置き、そこにテキストを入力させることができます。