Jean-Paul Ladue
2006-Jun-06 13:48 UTC
[Rails] Rails keeps adding the letter s to the MySQL tablename.
I followed this tutorial for Ruby on Rails... http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html?page=1 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. :-) 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! :-) Thank You. -- Posted via http://www.ruby-forum.com/.
Bryan Liles
2006-Jun-06 13:52 UTC
[Rails] Rails keeps adding the letter s to the MySQL tablename.
On Jun 6, 2006, at 9:47 AM, Jean-Paul Ladue wrote:> I followed this tutorial for Ruby on Rails... > > http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html?page=1 > > 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. :-) 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! :-) Thank > You.You can turn this off by adding the following to your config/ environment.rb file: ActiveRecord::Base.pluralize_table_names = false
Mohit Sindhwani
2006-Jun-06 13:56 UTC
[Rails] Rails keeps adding the letter s to the MySQL tablename.
Jean-Paul Ladue wrote:> I followed this tutorial for Ruby on Rails... > > http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html?page=1 > > 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. :-) 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! :-) Thank You. >It''s not a bug, it''s a feature! :-) 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 :) Or you follow the other mail''s suggestion and disable pluralized names. Cheers Mohit.
Bill Walton
2006-Jun-06 14:20 UTC
[Rails] Rails keeps adding the letter s to the MySQL tablename.
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 listRoR 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! ;-) hth, Bill
Jean-Paul Ladue
2006-Jun-06 14:26 UTC
[Rails] Re: Rails keeps adding the letter s to the MySQL tablename.
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. :-) -- Posted via http://www.ruby-forum.com/.
Apparently Analagous Threads
- ocfs-2.4.21-EL-smp-1.0.9-9.i686.rpm does not workwith RHEL 3errata kernel
- Keeping the traffis on or off the list ?
- update for 4.11 Security Officer-supported branches
- SSH key exchange algorithm negotiation payload growth
- ocfs-2.4.21-EL-smp-1.0.9-9.i686.rpm does not work with RHEL 3errata kernel