Migrate title attribute from rentable to video (and later, game)
authorIra W. Snyder <devel@irasnyder.com>
Wed, 21 Nov 2007 23:49:35 +0000 (15:49 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Wed, 21 Nov 2007 23:49:35 +0000 (15:49 -0800)
Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
app/controllers/video_controller.rb
app/models/rentable.rb
app/views/video/_form.rhtml
db/development.sqlite3
db/migrate/005_move_title_to_video.rb [new file with mode: 0644]
db/schema.rb

index a5508ae..529e695 100644 (file)
@@ -21,7 +21,11 @@ class VideoController < ApplicationController
   end
 
   def create
+    @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
       flash[:notice] = 'Video was successfully created.'
       redirect_to :action => 'list'
index 5beddc4..03c6607 100644 (file)
@@ -1,6 +1,5 @@
 class Rentable < ActiveRecord::Base
   has_many :coitem
 
-  validates_presence_of :title
-  validates_presence_of :genre
+  #validates_presence_of :genre
 end
index ab7e456..8e903a2 100644 (file)
@@ -1,6 +1,9 @@
 <%= error_messages_for 'video' %>
 
 <!--[form:video]-->
+<p><label for="video_title">Title</label><br/>
+<%= text_field 'video', 'title' %></p>
+
 <p><label for="video_newrelease">Newrelease</label><br/>
 <select id="video_newrelease" name="video[newrelease]"><option value="false" selected>False</option><option value="true">True</option></select></p>
 
index d7d382e..8334228 100644 (file)
Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ
diff --git a/db/migrate/005_move_title_to_video.rb b/db/migrate/005_move_title_to_video.rb
new file mode 100644 (file)
index 0000000..bb210d8
--- /dev/null
@@ -0,0 +1,11 @@
+class MoveTitleToVideo < ActiveRecord::Migration
+  def self.up
+    add_column :videos, :title, :string
+    remove_column :rentables, :title
+  end
+
+  def self.down
+    remove_column :videos, :title
+    add_column :rentables, :title, :string
+  end
+end
index c773ea1..ef81ab8 100644 (file)
@@ -2,7 +2,7 @@
 # migrations feature of ActiveRecord to incrementally modify your database, and
 # then regenerate this schema definition.
 
-ActiveRecord::Schema.define(:version => 4) do
+ActiveRecord::Schema.define(:version => 5) do
 
   create_table "coitems", :force => true do |t|
     t.column "customer_id", :integer
@@ -20,7 +20,6 @@ ActiveRecord::Schema.define(:version => 4) do
   end
 
   create_table "rentables", :force => true do |t|
-    t.column "title", :string
     t.column "genre", :string
   end
 
@@ -29,6 +28,7 @@ ActiveRecord::Schema.define(:version => 4) do
     t.column "newrelease",  :boolean, :default => false
     t.column "director",    :string
     t.column "genre",       :integer
+    t.column "title",       :string
   end
 
 end