开发者

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

开发者 https://www.devze.com 2022-12-20 02:44 出处:网络
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

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

精彩评论

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

关注公众号