From: Ira W. Snyder Date: Wed, 21 Nov 2007 23:49:35 +0000 (-0800) Subject: Migrate title attribute from rentable to video (and later, game) X-Git-Tag: turned-in~81 X-Git-Url: https://www.irasnyder.com/gitweb/?a=commitdiff_plain;h=620ca6eedb2bc3b9c31da71553c081f3442b95ce;p=cs356-p2-videostore.git Migrate title attribute from rentable to video (and later, game) Signed-off-by: Ira W. Snyder --- diff --git a/app/controllers/video_controller.rb b/app/controllers/video_controller.rb index a5508ae..529e695 100644 --- a/app/controllers/video_controller.rb +++ b/app/controllers/video_controller.rb @@ -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' diff --git a/app/models/rentable.rb b/app/models/rentable.rb index 5beddc4..03c6607 100644 --- a/app/models/rentable.rb +++ b/app/models/rentable.rb @@ -1,6 +1,5 @@ class Rentable < ActiveRecord::Base has_many :coitem - validates_presence_of :title - validates_presence_of :genre + #validates_presence_of :genre end diff --git a/app/views/video/_form.rhtml b/app/views/video/_form.rhtml index ab7e456..8e903a2 100644 --- a/app/views/video/_form.rhtml +++ b/app/views/video/_form.rhtml @@ -1,6 +1,9 @@ <%= error_messages_for 'video' %> +


+<%= text_field 'video', 'title' %>

+


diff --git a/db/development.sqlite3 b/db/development.sqlite3 index d7d382e..8334228 100644 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 index 0000000..bb210d8 --- /dev/null +++ b/db/migrate/005_move_title_to_video.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index c773ea1..ef81ab8 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 => 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