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
# 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
<%= error_messages_for 'rentable' %>
<!--[form:rentable]-->
-<p><label for="rentable_title">Title</label><br/>
-<%= text_field 'rentable', 'title' %></p>
-
-<p><label for="rentable_genre">Genre</label><br/>
-<%= text_field 'rentable', 'genre' %></p>
+<p><label for="rentable_type">Type</label><br/>
+<%= text_field 'rentable', 'rtype' %></p>
<!--[eoform:rentable]-->
<table>
<tr>
+ <th>ID</th>
+ <th>Title</th>
<% for column in Rentable.content_columns %>
<th><%= column.human_name %></th>
<% end %>
<% for rentable in @rentables %>
<tr>
+ <td><%=h rentable.id %></td>
+ <td>
+ <% if Game.find(:first, :conditions => "rentable_id='#{rentable.id}'") %>
+ Game
+ <% elsif Video.find(:first, :conditions => "rentable_id='#{rentable.id}'") %>
+ Video
+ <% else %>
+ ERROR
+ <% end %>
+ </td>
<% for column in Rentable.content_columns %>
<td><%=h rentable.send(column.name) %></td>
<% end %>
--- /dev/null
+class AddRentableType < ActiveRecord::Migration
+ def self.up
+ add_column :rentables, :rtype, :string
+ end
+
+ def self.down
+ remove_column :rentables, :rtype
+ end
+end
# 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
end
create_table "rentables", :force => true do |t|
+ t.column "rtype", :string
end
create_table "videos", :force => true do |t|