Modifying your model by creating or removing any fields in the database table or creating and running a new migration will not update the views or the controller for you.
You will have to manually make the modifications yourself by adding in that new attribute into your views.
Now depending on your configuration, it can be as easy as:
rails destroy scaffold_controller ModelName
This will delete all the views and controller associated with ModelName
.
In your case, you will run the command:
rails destroy scaffold_controller Pet
(This will delete all the views and the controller associated with the Pet
model.)
As you can see, this will also get rid of any code you might have in those views and controller.
Please use this at your own risk.
Now to recreate the controller and the views with the new field, you run:
rails g scaffold_controller Model attribute1 attribute2 attribute3
This will generate all the views with the three supplied attributes, e.g.
rails g scaffold_controller Pet pet_name pet_type pet_color
This will recreate the views with the pet_color
attribute in place.
Do remember to supply the attributes after the model name, otherwise, the views created will not reference any attributes. This is because when you use scaffold_controller
, you tell Rails not to use a model, hence, you have to supply the attributes manually.
For more information with regards to rails generate
and rails destroy
commands, do a rails generate -h
and rails destroy -h
respectively.
For more information about Rails commandline, please take a look at the guide available on The Rails Command Line
If this approach is unacceptable (you already have written a lot of code in the views, etc.), you will have to manually go in and update the views accordingly.
You can also look into backing up the existing views and controller and once you have destroyed and regenerated the views and the controller as described above, you can copy paste the relevant code back again.