From 28e07f23e1c75f7442dd87caf34f0f47109bf966 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Wed, 21 Nov 2007 19:30:29 -0800 Subject: [PATCH] Add "rentable type" to rentables Signed-off-by: Ira W. Snyder --- app/controllers/game_controller.rb | 1 + app/controllers/video_controller.rb | 1 + app/views/rentable/_form.rhtml | 7 ++----- app/views/rentable/list.rhtml | 12 ++++++++++++ db/development.sqlite3 | Bin 9216 -> 9216 bytes db/migrate/008_add_rentable_type.rb | 9 +++++++++ db/schema.rb | 3 ++- 7 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 db/migrate/008_add_rentable_type.rb 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 d82a2f85bb55085b636f7d474804883ce89ff1f2..c2859db854667304d3817fad232331698bb776a1 100644 GIT binary patch delta 372 zcmZqhXz-XIE!f6@3gjm0I5To=Ea+!uWZuN`pP7+k69)^+Vio}wHb&-049t%<3$ol` z=9gh)XJF(PWz=L$OUzF#o%~T;n1hM=3Ip?V<|{xICzy2vnb;U)85tR)Qgc!g70gT+ z7?{Nw*%&l|Lcyg4sYMFDiA9N-; zvGheQX2xR-Oy&cLa0ch(zlxT|ItoffC6xuK zN(yC(Madb7MH)t?rka|K1uX31l9G(g)?i&_nJKCH#SoHpa zVs2_Nm|&aiqP&NXm-z<+GxHq=<~z*KnBN2adyZL!gOQm*9BcwR6ElM-NHse%lmQH4 I4j^U$08FW1egFUf delta 401 zcmY+u&57~Lu&Iz>W4(4kI2mo=Xz=)OhQqEjw@fQebIsbPPOosEeoY&>^sO4XGJs=I}erOsCi>_S8s;{EwB#ts@BZ%?AWFU^4`H;Abp| zI3@UvUpO5`*gJ+OQbMU)K!>xC#MUT|2##@t<~;khj`uwXCqN5Tbiv!YAcuyqu6Z-P z>n?0VcpbE$M@!go;c^a{K;={zoSgA;y3o|CDJl~PXCOl>1!3f@^ob#Emnw`bEIbc? z-T90~hb$h$4JIq93f-Kgm+JgV)GXd;{SL|5R$qL86M_@>vp38}!ACRzI2QFXH~1YV z1Xtb55XOY=;U&OdCl(>w9yY#r)Av$ 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| -- 2.25.1
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) %>