How to update a CRUD with Scaffold?

Asked

Viewed 116 times

2

I have a system with Ruby and a CRUD has been created via Scaffold and I would like to add some new fields.

Because what I found on the internet was using the following command.

rails generate migration add_preco_to_produtos preco:decimal

However this command will only update the database, and I would like to update the entire CRUD. Is there any command that can assist me?

2 answers

2

This your doubt is very common for those who are starting with Rails, I’ve had the same question.

Scaffold is a feature that only serves to start a basic CRUD, you use a lot at first, but then you will begin to realize that it is too simple for most cases.

It does not update the code in case of changes for a good reason, or it would rewrite everything and you would lose everything you changed or it would be a complex tool to get "understand" what was changed and what was generated initially.

So the simple answer is: You will have to update your code in hand.

0

Hello the scaffold generates all the necessary parts for a crud, if you want to add more fields or modify a generated you will have to change manually and if you need to change the database you can generate a Migration for this.

rails g migration add_age_to_users age:int

The above command generates an Migration to add the age field in the users table.

Don’t forget to change the views and controlers for the field to appear and be saved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.