开发者

How do I add a new element to an existing class?

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

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


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"
...


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜