From 620ca6eedb2bc3b9c31da71553c081f3442b95ce Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Wed, 21 Nov 2007 15:49:35 -0800 Subject: [PATCH] Migrate title attribute from rentable to video (and later, game) Signed-off-by: Ira W. Snyder --- app/controllers/video_controller.rb | 4 ++++ app/models/rentable.rb | 3 +-- app/views/video/_form.rhtml | 3 +++ db/development.sqlite3 | Bin 7168 -> 7168 bytes db/migrate/005_move_title_to_video.rb | 11 +++++++++++ db/schema.rb | 4 ++-- 6 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 db/migrate/005_move_title_to_video.rb 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 d7d382e493cd7f2982fa66e4dcb6dd03363b9551..83342284224fa907c9b5c7e8083a81d5dedd9399 100644 GIT binary patch delta 330 zcmZp$Xt0;1QPF7|HN$33B)Ran279i6xxg;|`kCPd}WCAih@{5Y{i#QqKOo$Cf z7?>Y{joQI1C&R+Vz{sem$i!r1U|_CmXsBys2xpm3UM4KZ1JcC6!oa}%hWP-{{_V{E z$_)I9jGAeQ`KhG}V1hABAuYd1AuKg7CAFj^5vX34fnStS6UY!@1TsX~z=|0_ib2M) zGWantZ(>@-xS!z+gWtqL8_pUwc5!)m#zyza3nW7(i%ThS7O=95OG+{}TTj-NzBKux Uq}XJ0sW+SZBsdr+J4pBe0AHO;IRF3v delta 514 zcmaJ-O)mpc6n$^*j7n*mijO{(_DuwlsC4S1Be5VXEJP?Fv75H9+GywL^F$hp`qK7sG}}uKwm1&Z 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 -- 2.25.1