Simple scaffold question


#1

How do I get scaffold to generate code for a table whos name is not
plural
of the modelname I give to it. I.E., If I have an existing database, and
wish to generate scaffold code for existing tables, is this possible???


#2

In the model class do

set_table_name “MyTable”


#3

McClain wrote:

How do I get scaffold to generate code for a table whos name is not
plural
of the modelname I give to it. I.E., If I have an existing database, and
wish to generate scaffold code for existing tables, is this possible???

“ruby script/generate scaffold model model”

This circumvents the auto pluralization in the scaffold generator.


#4

McClain wrote:

How do I get scaffold to generate code for a table whos name is not
plural
of the modelname I give to it. I.E., If I have an existing database, and
wish to generate scaffold code for existing tables, is this possible???

Edit the ./config/environment.rb file in your application’s directory.
Down the bottom there is a commented-out section showing various ways to
set the plurals of words. This is perfect for eg. setting the plural of
“staff” to “staff” but might have other side-effects in your app other
than just getting the table name to work. If you don’t want to do this
then renaming the table to what ruby wants it to be (eg. rename
‘tblStaff’ to ‘staffs’), run the scaffold, rename the table back, then
add ‘set_table_name “tblStaff”’ to the model class.