How to add a field to Ruby on Rails?

I am new to RoR and I just used the scaffold to create a table and create pages for CRUD operations. Now I want to add a new field to this. One place I found tells you how to do this in the database, but is there a way to do this when it adds a field to all pages, or is it just a manual operation, and I need to make sure that I know all my fields in front?

+5
source share
4 answers

To add a new column to the database

$ script/generate migration add_fieldname_to_tablename fieldname:string 
$ rake db:migrate

To refresh your views, you can run the scaffold again by updating the list of fields. It will stop replacing your migrations, but you can force it to replace your views.

$ script/generate scaffold tablename fieldname:string old_field_1:string ...

a , . .

+13

, , , , .. , . , , , , .

+3

, , ( "rake db: migrate" !)

, : formtastic :

"f.inputs" " ", . , , , .

For a simplified understanding of the tutorial, see the latest relay (Railscast # 184, you need Google for this, I cannot post 2 links because I'm not cool enough for stackoverflow, sorry).

Railcast # 185 is expected to continue formtastic coverage and should be published next Monday.

+1
source

It needs to be done manually, or the scaffold needs to be regenerated.

0
source

All Articles