Forum: Ruby on Rails AR::Base.pluralize_table_names doesnt work with scaffold gen

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E5394e4d020f5007cfbda9c2522aff63?d=identicon&s=25 Philipp Ott (Guest)
on 2006-03-03 14:56
(Received via mailing list)

The script/generator scaffold for models doesnt respect (source in) this
config/environment.rb setup, right?

Because I can put in there ActiveRecord::Base.pluralize_table_names =
false but when I run a command like

ruby script/generate scaffold model Something

then it throws an error saying that my database scheme doesnt have a
Something. However there is a table called something.

If I then change my something table to somethings and rerun the command,
then it works fine. Then I have to edit model/Somthing.rb and inlcude
the set_table_name "Something" into the class definition, rename my
table back to something and also fix the test-classes because they got
generated with the somethings name. Seems to be a bit error prone to me
and very unelegant. pgAdmin makes the sql part easy, but it still feels
a bit strange to me.

Wouldnt it be nice if this automatism could be turned off for the
scaffold generator on request and we would be able to specify name of
the Model, name-as-is of the table, and maybe even name-as-is of the
primary key - and then the scaffold generator regards this and puts the
set_table_name and set_primary_key instructions into the models?

Or is there some way to tell this to the model generator already?

BTW: set_table_name works for me just fine without the
ActiveRecord::Base.pluralize_table_names = false assignment. In an empty
rails project, if I manually create a model and tie it to a controller
and view for editing and such, then use set_table_name, everything I m
doing works. So my next question is: for what is this assignment then?
How and when does it affect the model name to table name mapping?

This topic is locked and can not be replied to.