From: Ira W. Snyder Date: Thu, 22 Nov 2007 00:15:40 +0000 (-0800) Subject: Fix object relationships between video and rentable X-Git-Tag: turned-in~80 X-Git-Url: https://www.irasnyder.com/gitweb/?a=commitdiff_plain;h=2f9cf2b379b797bca623f032f7234f09e3b3c3af;hp=620ca6eedb2bc3b9c31da71553c081f3442b95ce;p=cs356-p2-videostore.git Fix object relationships between video and rentable Signed-off-by: Ira W. Snyder --- diff --git a/app/controllers/video_controller.rb b/app/controllers/video_controller.rb index 529e695..ad3aaee 100644 --- a/app/controllers/video_controller.rb +++ b/app/controllers/video_controller.rb @@ -21,9 +21,10 @@ class VideoController < ApplicationController end def create + # A new rentable must be created and saved whenever we create a new + # video. This is so we have a rentable_id to add to the video. @rentable = Rentable.new @rentable.save! - puts "created new rentable with ID: #{@rentable.id}" @video = Video.new(params[:video]) @video.rentable_id = @rentable.id if @video.save diff --git a/app/models/rentable.rb b/app/models/rentable.rb index 03c6607..0674d8e 100644 --- a/app/models/rentable.rb +++ b/app/models/rentable.rb @@ -1,5 +1,6 @@ class Rentable < ActiveRecord::Base has_many :coitem + belongs_to :video #validates_presence_of :genre end diff --git a/app/models/video.rb b/app/models/video.rb index 4ecf31b..2ab598d 100644 --- a/app/models/video.rb +++ b/app/models/video.rb @@ -1,5 +1,5 @@ class Video < ActiveRecord::Base - belongs_to :rentable + has_one :rentable validates_presence_of :director validates_presence_of :genre diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 8334228..3d63cdb 100644 Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ