Forum: Ruby on Rails Rails still trying to access table that has been renamed

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.
E49352a077a28a9c0b10831b4750f142?d=identicon&s=25 chhenning (Guest)
on 2007-01-22 17:43
(Received via mailing list)
Hi there, I'm quite new to ruby on rails. The version I'm running is
1.2. I have created my database schema using the rails migrate
facilities. I have many tables with plenty of columns. During the
course of creating tables I needed to make changes to existing tables,
like renaming a table to a different name. For example I renamed my
"People" table to "Persons" .

I have created a scaffolding controller to Persons. But for whatever
reason rails is still trying to access a table called People.

This is my error:
Mysql::Error: #42S02Table 'md_development.people' doesn't exist: SHOW
FIELDS FROM people

How is that possible?

Thanks ahead,
Christian
8e73782b5a220c5d923a0195667e7406?d=identicon&s=25 Kim (Guest)
on 2007-01-22 18:39
(Received via mailing list)
It has to do with Rails naming convention. To much of a newbe myself,
to explain well. I know you are supposed to  name your DB tables with
the singular form of a word, and then refer to the table in the
pluralized form.

So when you try to refer to the DB by Persons, Rails looks for a table
called People. It has nothing to do with the renaming, except that you
renamed the table in the plural. Change it back to People and
everything will work fine.

Hope that helps - K.
E49352a077a28a9c0b10831b4750f142?d=identicon&s=25 chhenning (Guest)
on 2007-01-22 19:18
(Received via mailing list)
Thank you so much Kim. Yeah that was it. As I'm non-native english
speaker I think it's kind of easy to make that failure. A quick search
on google revealed:

people - 1.280.000.000 hits
persons - 221.000.000 hits

Guess Rails is right. ;-)

Thanks again,
Christian
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2007-01-22 19:39
(Received via mailing list)
On Jan 22, 2007, at 1:16 PM, chhenning wrote:

> Thanks again,
> Christian

Well, "persons" is grammatically correct when the number of
individuals is countable.  It is more correct to say that my car
"seats 5 persons" than to say "seats 5 people".  However, you have a
"crowd of people", not a "crowd of persons".

Depending on the usage, the plural of "person" can be either
"persons" or "people", but the Inflector in Rails will only use the
more common "people".  As those who have models named in non-English
languages continually discover, the Inflector isn't perfect.  Even
for many "English" words derived from Latin, the standard rules
"fail".  (I ran into "criterion"/"criteria" that Rails thought should
be "criteria"/"criterias" or "criterium"/"criteria" on a previous
project.)

If your application makes sense to speak of "persons", then you need
to declare that in your model:

class Person < ActiveRecord::Base
   set_table_name "persons"
end

-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
E49352a077a28a9c0b10831b4750f142?d=identicon&s=25 chhenning (Guest)
on 2007-01-22 19:58
(Received via mailing list)
Thanks Rob, I changed it back to persons since i think it makes more
sense in my application.

Christian
This topic is locked and can not be replied to.