Change Scaffolded String to Decimal
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 |
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. |
Mikhail V. S...
19 posts
|
To change ‘rating’ from string to decimal you should (2) describe the changing of the column in the generated migration file: (3) run the migration by ’ rake db:migrate ‘ |
3 posts, 3 voices
