Adding a new field to Rails model

前端 未结 4 1994
臣服心动
臣服心动 2021-01-30 11:03

I already created a scafold using

rails generate scaffold myOdb2 columna:integer, columnB:string

now I want to add columnc:string

4条回答
  •  广开言路
    2021-01-30 11:57

    Scaffolding, quick and easy, generates data model and web interface all in once. However, rails generate scaffold is just a way to get started with your model and it helps just at the beginning.

    Normally, you first have to extend the data model. This task is simplified by using rails generate migration and rake db:migration. Note that you may prefer to use rake with bundle exec to ensure to use the version of rake in your Gemfile.

    Thereafter, you probably want to update (maybe also create new) controllers and views directly, according to the requirements of your web application.

    aka MVC

    For example, in brand new scaffolded model you may want to update the index and show views (see the app/views folder) and the myOdb2 controller (see the app/controllers folder)

    Do not forget to read about migratons http://guides.rubyonrails.org/migrations.html

提交回复
热议问题