Fix object relationships between video and rentable
authorIra W. Snyder <devel@irasnyder.com>
Thu, 22 Nov 2007 00:15:40 +0000 (16:15 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Thu, 22 Nov 2007 00:15:40 +0000 (16:15 -0800)
Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
app/controllers/video_controller.rb
app/models/rentable.rb
app/models/video.rb
db/development.sqlite3

index 529e695..ad3aaee 100644 (file)
@@ -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
index 03c6607..0674d8e 100644 (file)
@@ -1,5 +1,6 @@
 class Rentable < ActiveRecord::Base
   has_many :coitem
+  belongs_to :video
 
   #validates_presence_of :genre
 end
index 4ecf31b..2ab598d 100644 (file)
@@ -1,5 +1,5 @@
 class Video < ActiveRecord::Base
-  belongs_to :rentable
+  has_one :rentable
 
   validates_presence_of :director
   validates_presence_of :genre
index 8334228..3d63cdb 100644 (file)
Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ