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??? _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
you can turn off pluralization by adding the following to your environment.rb file - ActiveRecord::Base.pluralize_table_names = false On 29/12/05, McClain <jmcclain1-9byIcQoa8qfk1uMJSBkQmQ@public.gmane.org> 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??? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
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??? _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
In the model class do set_table_name "MyTable" On 12/30/05, McClain <jmcclain1-9byIcQoa8qfk1uMJSBkQmQ@public.gmane.org> 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??? > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
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. -- Posted via http://www.ruby-forum.com/.
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. -- Posted via http://www.ruby-forum.com/.