# 2 questions about generate scaffold

**URL:** <https://www.ruby-forum.com/t/2-questions-about-generate-scaffold/84941>\
**Category:** Rails\
**Created:** [February 8, 2007, 7:28pm UTC](https://www.ruby-forum.com/t/2-questions-about-generate-scaffold/84941 "2007-02-08T19:28:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [February 8, 2007, 7:28pm UTC](https://www.ruby-forum.com/t/2-questions-about-generate-scaffold/84941/1 "2007-02-08T19:28:51Z")

</div>

i know this may be easy, but i cant find how to do this.

i have a table called status\_def  
i want to generate a scaffold for it, but it will not let me create  
one because (i think) the table name is not plural.

is there a command line option to script/generate that will allow me  
to create a scaffold if the table is not plural ?

btw - all my other tables obey conventions nice, but too much code  
will have to be re-written to change the name of this table.

next question.  
one of the fields in the status\_def table is oem. if i generate a  
scaffold for this table, can i put something in the model that will  
only allow records of oem = ‘somecompany’ to be selected ?

thanks for any tips

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [February 9, 2007, 2:25am UTC](https://www.ruby-forum.com/t/2-questions-about-generate-scaffold/84941/2 "2007-02-09T02:25:38Z")

</div>

On Feb 9, 5:28 am, “nephish” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> will have to be re-written to change the name of this table.
> 
> next question.  
> one of the fields in the status\_def table is oem. if i generate a  
> scaffold for this table, can i put something in the model that will  
> only allow records of oem = ‘somecompany’ to be selected ?
> 
> thanks for any tips

I think this is not really a problem with the scaffold but the model,  
which will be pluralised by default.

Once you have generated your scaffold, edit the /app/models/  
status\_def.rb file to :

class StatusDef\< ActiveRecord::Base  
set\_table\_name “status\_def”  
end

I don’t know the answer to your second question, but it implies there  
is a related company. If this is the case you could use the ID of the  
company when selecting from status\_def. Maybe use act\_as\_list, or  
scope would be useful here?

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [February 9, 2007, 6:09am UTC](https://www.ruby-forum.com/t/2-questions-about-generate-scaffold/84941/3 "2007-02-09T06:09:53Z")

</div>

On Feb 9, 3:36 pm, “nephish” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > one because (i think) the table name is not plural.  
> > > only allow records of oem = ‘somecompany’ to be selected ?  
> > > set\_table\_name “status\_def”  
> > > for your model (StatusDef)  
> > > and i do have the table in the database .  
> > > weird.
> 
> thanks, i found another way around the second question  
> sk

Ahh, opps, yes. The scaffold it built from the model, which is in  
that naming format.  
I know the capitals are a requirement of Ruby, but I am not sure about  
the removal of underscores - probably convention again 🙂

Rails will pluralise the model name to guess the table name, so:

./script/generate scaffold status\_def  
model = StatusDef  
DB table = statusdefs ← wrong in this case.

There does not seem to be a switch on generate to override this  
behaviour, so you need to do it in three steps (punishment for going  
outside the conventions) :

./script/generate model status\_def  
model = StatusDef

Edit the /app/models/status\_def.rb file, add:  
set\_table\_name “status\_def”

./script/generate scaffold status\_def

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [February 9, 2007, 6:20am UTC](https://www.ruby-forum.com/t/2-questions-about-generate-scaffold/84941/4 "2007-02-09T06:20:54Z")

</div>

On Feb 8, 11:09 pm, “askegg” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > > i have a table called status\_def  
> > > > one of the fields in the status\_def table is oem. if i generate a
> 
> > scaffold status\_def it spit out this  
> > I know the capitals are a requirement of Ruby, but I am not sure about  
> > outside the conventions) :
> 
> ./script/generate model status\_def  
> model = StatusDef
> 
> Edit the /app/models/status\_def.rb file, add:  
> set\_table\_name “status\_def”
> 
> ./script/generate scaffold status\_def

thanks for the help, this table stands alone, no has\_many, has\_one,  
hmbtm, etc… just all alone and a scaffold does all the CRUD i need.  
i appreciate your help. Really, i was good on the other tables, really  
i was, i even have the book ! don’t know what i was thinking still,  
but i am all up and running now.  
thanks again

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [February 9, 2007, 5:36am UTC](https://www.ruby-forum.com/t/2-questions-about-generate-scaffold/84941/5 "2007-02-09T05:36:50Z")

</div>

On Feb 8, 7:24 pm, “askegg” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > is there a command line option to script/generate that will allow me  
> > thanks for any tips
> 
> I don’t know the answer to your second question, but it implies there  
> is a related company. If this is the case you could use the ID of the  
> company when selecting from status\_def. Maybe use act\_as\_list, or  
> scope would be useful here?

ok, well the reason i asked was because when i did the script/generate  
scaffold status\_def it spit out this  
Before updating scaffolding from new DB schema, try creating a table  
for your model (StatusDef)  
and i do have the table in the database .  
weird.

thanks, i found another way around the second question  
sk
