0

私の協会に何か問題があります。
多くのVideoPostが同じVideoInformationを参照できるようにしたいと思います。次に、外部キーをVideoPostに含める必要があると考えたので、以下に示す2つのモデルから始めました。しかし、@ video_post.video_informationにアクセスできません(VideoPostには関連付けがないため、これは理にかなっているようです)
どうすればよいですか?私はここで少し混乱しています

助けてくれてありがとう!

私のVideoPostモデル:

# Table name: video_posts
#
#  id                   :integer          not null, primary key
#  user_id              :integer
#  video_information_id :integer
#  created_at           :datetime         not null
#  updated_at           :datetime         not null
class VideoPost < ActiveRecord::Base
  belongs_to :user

  attr_accessible :video_information_id
end

私のVideoInformationモデル:

# Table name: video_informations
#
#  id              :integer          not null, primary key
#  title           :string(255)
#  description     :text
#  keywords        :text
#  duration        :integer
#  video_url       :string(255)
#  thumbnail_small :string(255)
#  thumbnail_large :string(255)
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
class VideoInformation < ActiveRecord::Base
  has_many :video_posts
end
4

1 に答える 1

1

追加する必要があります

belongs_to :video_information

関連付けを定義するときは、両方のモデルで行う必要があるため、video_post.rbに追加します。

ここにあなたがおそらく見たいと思ういくつかの情報があります

于 2012-10-30T19:23:32.500 に答える