views:

28

answers:

2

I already generated a class by "script/generate model blah blah1:string"

How would I add a "blah2:string" to the existing model? Is there a script or do I have to manually edit the database and every file?

A: 

You can create new migration of change table.. Check this.. See section 3.2

Teja Kantamneni
I read that, I'm not sure where I enter the code. Do I create a new file with the code in it and execute it with Ruby?
cam
Create a migration and your code in that migration. Run the rake task to execute it
Teja Kantamneni
+4  A: 

Create migration:

./script/generate migration AddBlah2ToBlah blah2:string

This will create migration in db/migrate ruby file with migration - you can check if it correctly added column to table. Then run:

rake db:migrate

or in production environment:

rake db:migrate RAILS_ENV=production 

This will add column to your database and you can use it in Rails:

@blah = Blah.first
@blah.blah2 = "new string"
...
klew