From: Ira W. Snyder
Date: Thu, 22 Nov 2007 04:18:18 +0000 (-0800)
Subject: Switch to a single joined table for Videos and Games
X-Git-Tag: turned-in~75
X-Git-Url: https://www.irasnyder.com/gitweb/?a=commitdiff_plain;h=3650c5f411112965a12718b75ccbedde3186fa15;p=cs356-p2-videostore.git
Switch to a single joined table for Videos and Games
This is much simpler than the multiple inheritance thing, as well as making
things like getting all of the types and titles much easier.
Signed-off-by: Ira W. Snyder
---
diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb
index 1b57435..175a63f 100644
--- a/app/controllers/game_controller.rb
+++ b/app/controllers/game_controller.rb
@@ -21,12 +21,7 @@ class GameController < ApplicationController
end
def create
- # A new rentable must be created whenever we create a new game
- @rentable = Rentable.new
- @rentable.rtype = 'game'
- @rentable.save
@game = Game.new(params[:game])
- @game.rentable_id = @rentable.id
if @game.save
flash[:notice] = 'Game was successfully created.'
redirect_to :action => 'list'
diff --git a/app/controllers/video_controller.rb b/app/controllers/video_controller.rb
index 4221c3c..a5508ae 100644
--- a/app/controllers/video_controller.rb
+++ b/app/controllers/video_controller.rb
@@ -21,13 +21,7 @@ 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.rtype = 'video'
- @rentable.save!
@video = Video.new(params[:video])
- @video.rentable_id = @rentable.id
if @video.save
flash[:notice] = 'Video was successfully created.'
redirect_to :action => 'list'
diff --git a/app/models/game.rb b/app/models/game.rb
index 9880b04..4991aa9 100644
--- a/app/models/game.rb
+++ b/app/models/game.rb
@@ -1,7 +1,4 @@
-class Game < ActiveRecord::Base
- has_one :rentable
-
- validates_presence_of :title
- validates_presence_of :genre
+class Game < Rentable
+ validates_presence_of :game_genre
validates_presence_of :platform
end
diff --git a/app/models/rentable.rb b/app/models/rentable.rb
index 0699a20..cccbb57 100644
--- a/app/models/rentable.rb
+++ b/app/models/rentable.rb
@@ -1,6 +1,6 @@
class Rentable < ActiveRecord::Base
has_many :coitem
- belongs_to :video
- belongs_to :game
+ validates_presence_of :title
+ # don't validate newrelease, false is ok
end
diff --git a/app/models/video.rb b/app/models/video.rb
index 2ab598d..50733d5 100644
--- a/app/models/video.rb
+++ b/app/models/video.rb
@@ -1,6 +1,5 @@
-class Video < ActiveRecord::Base
- has_one :rentable
-
+class Video < Rentable
validates_presence_of :director
- validates_presence_of :genre
+ validates_presence_of :video_genre
+ validates_presence_of :media
end
diff --git a/app/views/game/_form.rhtml b/app/views/game/_form.rhtml
index a0ab990..b264601 100644
--- a/app/views/game/_form.rhtml
+++ b/app/views/game/_form.rhtml
@@ -4,10 +4,13 @@