# Change model definition using scaffold

**URL:** <https://www.ruby-forum.com/t/change-model-definition-using-scaffold/145505>\
**Category:** Rails\
**Created:** [August 11, 2008, 12:42am UTC](https://www.ruby-forum.com/t/change-model-definition-using-scaffold/145505 "2008-08-11T00:42:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gromski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d26b3c/32.png) [@Gromski](https://www.ruby-forum.com/u/Gromski)\
**Post date:** [August 11, 2008, 12:42am UTC](https://www.ruby-forum.com/t/change-model-definition-using-scaffold/145505/1 "2008-08-11T00:42:38Z")

</div>

Hi all

Apologies if this a trivially newb question but I’m new to rails (and  
frameworks in general) but is there a way to change the model  
definition using the scaffold, i.e. is it possible to update the  
model, views etc if I decide I need to add field d to fields a, b and  
c that I already created using script/generate scaffold…?

At the moment I’m having to delete the generated code, rollback the DB  
migration ad generate it from scratch again - I’m sure there must be  
an easier/faster way.

Cheers

Mark

---

<div class="post-metadata">

**Author:** ![Gromski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d26b3c/32.png) [@Gromski](https://www.ruby-forum.com/u/Gromski)\
**Post date:** [August 11, 2008, 12:46am UTC](https://www.ruby-forum.com/t/change-model-definition-using-scaffold/145505/2 "2008-08-11T00:46:09Z")

</div>

I understood the question’s answer seems to be:

yes, you can edit the files themselves to reflect the changes you made  
to the model. If you added a new field x to the model, then you can  
change the files like \_form.html.erb to have the x field in it.

On Mon, Aug 11, 2008 at 5:28 AM, Gromski [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> migration ad generate it from scratch again - I’m sure there must be  
> an easier/faster way.
> 
> Cheers
> 
> Mark

–  
Ramon T.

---

<div class="post-metadata">

**Author:** ![Gromski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d26b3c/32.png) [@Gromski](https://www.ruby-forum.com/u/Gromski)\
**Post date:** [August 13, 2008, 1:51am UTC](https://www.ruby-forum.com/t/change-model-definition-using-scaffold/145505/3 "2008-08-13T01:51:06Z")

</div>

Hi Ramon

Not quite. I understand that the files can be edited ‘manually’ but I  
was wondering if there was a short hand using the scaffold so that I  
wouldn’t have to, e.g. I re-run script/generate with a different param  
to add a field to all of the relevant files…

Cheers

M

On Aug 10, 11:45 pm, “Ramon Miguel M. Tayag” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Gromski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d26b3c/32.png) [@Gromski](https://www.ruby-forum.com/u/Gromski)\
**Post date:** [August 13, 2008, 3:52am UTC](https://www.ruby-forum.com/t/change-model-definition-using-scaffold/145505/4 "2008-08-13T03:52:49Z")

</div>

On Aug 12, 6:50 pm, Gromski [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi Ramon
> 
> Not quite. I understand that the files can be edited ‘manually’ but I  
> was wondering if there was a short hand using the scaffold so that I  
> wouldn’t have to, e.g. I re-run script/generate with a different param  
> to add a field to all of the relevant files…

No, but you could:

1. Revert your migration with rake db:migrate:rollback (to go back one  
version; or use VERSION= explicitly)
2. script/destroy scaffold ModelName

Then you can script/generate your scaffold again.

But that’s a lot of work… easier to just manually update a few  
files. If you first refactor your new and edit forms out into a  
partial, you’ll save yourself some editing.

Jeff

REST with Rails  
Saturday, Oct 4, 2008  
Austin, Texas  
[http://www.purpleworkshops.com/workshops/rest-and-web-services](http://www.purpleworkshops.com/workshops/rest-and-web-services)

---

<div class="post-metadata">

**Author:** ![Gromski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/d26b3c/32.png) [@Gromski](https://www.ruby-forum.com/u/Gromski)\
**Post date:** [August 13, 2008, 4:50am UTC](https://www.ruby-forum.com/t/change-model-definition-using-scaffold/145505/5 "2008-08-13T04:50:42Z")

</div>

Hi –

On Sun, 10 Aug 2008, Gromski wrote:

> migration ad generate it from scratch again - I’m sure there must be  
> an easier/faster way.

In most cases if you want to modify an existing schema you would  
create a new migration file:

script/generate migration add\_email\_column\_to\_user

and then put what you need in the newly-created file and then run  
“rake db:migrate”.

If you’re at the very beginning of a project, and decide you want to  
change something, you might migrate backwards and start again. Once  
the project is underway, though, migrating backwards ends up being  
more confusing than it’s worth in almost every case.

As for the scaffolding, I wouldn’t recommend using it as the basis for  
a real application, except in cases where what it produces is exactly  
what you want. If you find yourself developing an app by starting with  
the scaffolding and making lots of changes (or wondering whether what  
you’re doing is OK because it deviates from the scaffolding), it’s a  
sign that you should abandon the scaffolding and just develop the app.  
Or you can skip that process and just abandon the scaffolding from the  
start 🙂

David

–  
Rails training from David A. Black and Ruby Power and Light:

- Advancing With Rails August 18-21 Edison, NJ
- Co-taught by D.A. Black and Erik Kastner  
See [http://www.rubypal.com](http://www.rubypal.com) for details and updates!
