From: Ira W. Snyder Date: Thu, 22 Nov 2007 03:30:29 +0000 (-0800) Subject: Add "rentable type" to rentables X-Git-Tag: turned-in~76 X-Git-Url: https://www.irasnyder.com/gitweb/?a=commitdiff_plain;h=28e07f23e1c75f7442dd87caf34f0f47109bf966;p=cs356-p2-videostore.git Add "rentable type" to rentables Signed-off-by: Ira W. Snyder --- diff --git a/app/controllers/game_controller.rb b/app/controllers/game_controller.rb index 50f6a95..1b57435 100644 --- a/app/controllers/game_controller.rb +++ b/app/controllers/game_controller.rb @@ -23,6 +23,7 @@ class GameController < ApplicationController 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 diff --git a/app/controllers/video_controller.rb b/app/controllers/video_controller.rb index ad3aaee..4221c3c 100644 --- a/app/controllers/video_controller.rb +++ b/app/controllers/video_controller.rb @@ -24,6 +24,7 @@ class VideoController < ApplicationController # 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 diff --git a/app/views/rentable/_form.rhtml b/app/views/rentable/_form.rhtml index ecfbfae..a5b3ba2 100644 --- a/app/views/rentable/_form.rhtml +++ b/app/views/rentable/_form.rhtml @@ -1,10 +1,7 @@ <%= error_messages_for 'rentable' %> -


-<%= text_field 'rentable', 'title' %>

- -


-<%= text_field 'rentable', 'genre' %>

+


+<%= text_field 'rentable', 'rtype' %>

diff --git a/app/views/rentable/list.rhtml b/app/views/rentable/list.rhtml index 39883c5..19f6f75 100644 --- a/app/views/rentable/list.rhtml +++ b/app/views/rentable/list.rhtml @@ -2,6 +2,8 @@ + + <% for column in Rentable.content_columns %> <% end %> @@ -9,6 +11,16 @@ <% for rentable in @rentables %> + + <% for column in Rentable.content_columns %> <% end %> diff --git a/db/development.sqlite3 b/db/development.sqlite3 index d82a2f8..c2859db 100644 Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ diff --git a/db/migrate/008_add_rentable_type.rb b/db/migrate/008_add_rentable_type.rb new file mode 100644 index 0000000..57600e8 --- /dev/null +++ b/db/migrate/008_add_rentable_type.rb @@ -0,0 +1,9 @@ +class AddRentableType < ActiveRecord::Migration + def self.up + add_column :rentables, :rtype, :string + end + + def self.down + remove_column :rentables, :rtype + end +end diff --git a/db/schema.rb b/db/schema.rb index fff73ef..885c6ee 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2,7 +2,7 @@ # migrations feature of ActiveRecord to incrementally modify your database, and # then regenerate this schema definition. -ActiveRecord::Schema.define(:version => 7) do +ActiveRecord::Schema.define(:version => 8) do create_table "coitems", :force => true do |t| t.column "customer_id", :integer @@ -27,6 +27,7 @@ ActiveRecord::Schema.define(:version => 7) do end create_table "rentables", :force => true do |t| + t.column "rtype", :string end create_table "videos", :force => true do |t|
IDTitle<%= column.human_name %>
<%=h rentable.id %> + <% if Game.find(:first, :conditions => "rentable_id='#{rentable.id}'") %> + Game + <% elsif Video.find(:first, :conditions => "rentable_id='#{rentable.id}'") %> + Video + <% else %> + ERROR + <% end %> + <%=h rentable.send(column.name) %>