简体   繁体   English

如何在现有rails应用程序中添加新字段

[英]How to add a new field in an existing rails application

I have developed a web application with fields Keyword,Latitude and Longitude. 我开发了一个带有关键字,纬度和经度字段的Web应用程序。 I want to add one more field called Radius to the web application.. How should i proceed. 我想在Web应用程序中再添加一个名为Radius的字段。我该怎么办?

Waiting for the reply, 等待回复,

Thanks in advance 提前致谢

really simple to do it. 真的很简单。 Simply do: 简单地说:

script/generate migration AddRadiusToAddress Radius:string

The example above supposed your model is called address, hence the "AddRadiusToAddress", but if your model is called something else, simply change address with that "something else" 上面的示例假设您的模型称为地址,因此称为“AddRadiusToAddress”,但如果您的模型被称为其他内容,则只需使用“其他内容”更改地址

And the field name in this case is radius, and I;m setting iut to be string, you might wanna change this as well. 在这种情况下,字段名称是半径,而I; m将iut设置为字符串,您可能也想更改它。

After that, simply rung: 在那之后,简单地说:

rake db:migrate

Hope this helps you. 希望这对你有所帮助。

UPDATE UPDATE

And just for the sake of it, I thought I'd add an example of removing a field as well: 仅仅为了它,我想我还要添加一个删除字段的示例:

script/generate migration RemoveRadiusFromAddress role:string

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM