Forum: Ruby on Rails simple scaffold question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A93c4933226843c95560a101b7ea1733?d=identicon&s=25 McClain (Guest)
on 2005-12-30 03:47
(Received via mailing list)
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???
6828ffc79486cd2442714bf32286a910?d=identicon&s=25 Vivek Krishna (Guest)
on 2005-12-30 08:03
(Received via mailing list)
In the model class do

  set_table_name "MyTable"
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (Guest)
on 2005-12-30 15:17
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.
171c44a0c5fe6f202212984f02cf35a2?d=identicon&s=25 bob (Guest)
on 2006-01-20 01:48
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.
This topic is locked and can not be replied to.