Rails keeps adding the letter s to the MySQL tablename

I followed this tutorial for Ruby on Rails…

Everything went fine. I created the DB in MySQL and tested the
recipe/new and recipe/list functions, and all went smooth.

Now I’m trying to use Ruby on Rails to track software licenses here at
work and I keep running into this strange problem. I am setting up the
DB, model, and controller files just fine…

development:
adapter: mysql
database: gcsaam
username: root
password:
host: localhost

Warning: The database defined as ‘test’ will be erased and

re-generated from your development database when you run ‘rake’.

Do not set this db to the same as development or production.

test:
adapter: mysql
database: gcsaam
username: root
password:
host: localhost

production:
adapter: mysql
database: gcsaam
username: root
password:
host: localhost

softlic.rb

class Softlic < ActiveRecord::Base
end

softlic_controller.rb

class SoftlicController < ApplicationController
scaffold :softlic
end

So here is my problem. Ruby or maybe Rails, keeps addign the letter “s”
to the MySQL table name like it shows here…

ActiveRecord::StatementInvalid in SoftlicController#new

Mysql::Error: #42S02Table ‘gcsaam.softlics’ doesn’t exist: SHOW FIELDS
FROM softlics

RAILS_ROOT: ./script/…/config/…

My table name is softlic, not softlics. I’ve been at this for a day and
a half and am about to toss something across the room. :slight_smile: I am totally
stumped here. I even thought maybe it was a bug issue with 1.8.4-17 so
I downgraded to 1.8.2-15. Does anybody know what my problem might be?
Am I missing some small morsel of info here? My new project is pretty
much a mirror image of the cookbook example with the exception of
filename changes and different fields in the DB. Help! :slight_smile: Thank You.

On Jun 6, 2006, at 9:47 AM, Jean-Paul Ladue wrote:

DB, model, and controller files just fine…

Do not set this db to the same as development or production.

username: root
class SoftlicController < ApplicationController
FROM softlics
Am I missing some small morsel of info here? My new project is pretty
much a mirror image of the cookbook example with the exception of
filename changes and different fields in the DB. Help! :slight_smile: Thank
You.

You can turn this off by adding the following to your config/
environment.rb file:
ActiveRecord::Base.pluralize_table_names = false

Jean-Paul Ladue wrote:

test:
password:
scaffold :softlic
RAILS_ROOT: ./script/…/config/…

My table name is softlic, not softlics. I’ve been at this for a day and
a half and am about to toss something across the room. :slight_smile: I am totally
stumped here. I even thought maybe it was a bug issue with 1.8.4-17 so
I downgraded to 1.8.2-15. Does anybody know what my problem might be?
Am I missing some small morsel of info here? My new project is pretty
much a mirror image of the cookbook example with the exception of
filename changes and different fields in the DB. Help! :slight_smile: Thank You.

It’s not a bug, it’s a feature! :slight_smile:

You may have noticed that the ONLamp tutorial used “recipes” as the name
of the table, but accessed it using “recipe” when scaffolding. RoR
likes to maintain data in tables that are plurals of the basic record.
So, the class “item” goes into a table called “itemS”, class “recipe”
into “recipes” and so on…

Your table needs to be name with an “s” - that’s all :slight_smile:

Or you follow the other mail’s suggestion and disable pluralized names.
Cheers
Mohit.

Hi Jean-Paul,

Jean-Paul Ladue wrote:

So here is my problem. Ruby or maybe Rails,
keeps addign the letter “s” to the MySQL table
name like it shows here…

Mysql::Error: #42S02Table ‘gcsaam.softlics’ doesn’t exist

My table name is softlic, not softlics.

Am I missing some small morsel of info here? > Rails mailing list

RoR favors convention over configuration. This is one of the biggies.

Table names are plural version of the model names because a model object
represents one row in a table. It’s a fundamental convention that’s a
reflection of the Active Record pattern. In your case, the table
contains a
collection of software licenses. Each model object represents one
software
license. Makes sense, no?

There are ways, as noted by other responders, to over-ride the behavior.
It’s not advisable except in extreme circumstances.

Learn it. You’ll love it! :wink:

hth,
Bill

Thanks guys, everything is as smooth as silk now. I had read about the
pluralization but wasn’t aware that it worked this way. Thanks again
and you’ll probably see me again soon. :slight_smile: