Generic-user-small Aaron Miller 1 post

When I generated my scaffold, I created ratings as strings. I would like to change that, so that ratings are now stored as decimals. I tried changing the schema and migration files (as shown below), but this does not seem to work. Suggestions?

FROM:

create_table “posts”, :force => true do |t| t.string “rating” t.datetime “created_at” t.datetime “updated_at” end

class CreatePosts < ActiveRecord::Migration def self.up create_table :posts do |t| t.string :rating t.timestamps end

TO:

create_table “posts”, :force => true do |t| t.decimal “rating” t.datetime “created_at” t.datetime “updated_at” end

class CreatePosts < ActiveRecord::Migration def self.up create_table :posts do |t| t.decimal :rating t.timestamps end

Thanks,

Aaron

 
Generic-user-small James West 70 posts

Personally I would generate a new migration to change the column type. This is covered in the book somewhere! then run the migration to phyiscally change the column.

 
M_v_shokhirev_small Mikhail V. S... 19 posts

To change ‘rating’ from string to decimal you should
(1) script/generate migration ChangePosts

(2) describe the changing of the column in the generated migration file:
class ChangePosts < ActiveRecord::Migration; def self.up; change_column :posts, :rating, :decimal; end; def self.down; change_column :posts, :rating, :string; end;
end;

(3) run the migration by ’ rake db:migrate ‘

3 posts, 3 voices