From 2f9cf2b379b797bca623f032f7234f09e3b3c3af Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Wed, 21 Nov 2007 16:15:40 -0800 Subject: [PATCH] Fix object relationships between video and rentable Signed-off-by: Ira W. Snyder --- app/controllers/video_controller.rb | 3 ++- app/models/rentable.rb | 1 + app/models/video.rb | 2 +- db/development.sqlite3 | Bin 7168 -> 7168 bytes 4 files changed, 4 insertions(+), 2 deletions(-) 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 83342284224fa907c9b5c7e8083a81d5dedd9399..3d63cdb243ac1a3e958fd61d637dffb4e22fff51 100644 GIT binary patch delta 92 zcmZp$Xt0^ys!S%55t%_sP6SU4D&A2KjMWWKpskYzjbI@7FAj}}k$j-pXugoaRmgZZj;F4LCnp~1!R1IW@Wu~O&FOpyZ06cFOW&i*H delta 92 zcmZp$Xt0^ys!Sr`}?ST~>Gw_)L60J53iFdx_~$g-Vz@?mi? p^&*9^)V!3`l9EKADp>}8QASN5Lxd5?5M@hC%ug+401=BMSO7nF7A^n) -- 2.25.1