Railers: Greetings from the low end of the learning curve. I have installed all the prerequisites on Win32, including a lite MySQL database with a table in it called Inventory. Then I run this command line... ruby script/generate ajax_scaffold Inventory ...and I get this error message: error Before updating scaffolding from new DB schema, try creating a table for your model (Inventory) So I read log/development.log, and it contains this: Error: Table ''rails_development.inventories'' doesn''t exist The system is inexplicably pluralizing my table name. Am I using the system wrong, or is this a false "feature"? Can I fix it by adding a view called ''inventories''? Or must I rename the table? And how, in general, can Rails present data views that don''t have the same shape as the target database schema? Such schemas should be normalized beyond recognition... -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!
> Greetings from the low end of the learning curve. I have installed all > the prerequisites on Win32, including a lite MySQL database with a > table in it called Inventory. > > Then I run this command line... > > ruby script/generate ajax_scaffold Inventory > > ...and I get this error message: > > error Before updating scaffolding from new DB schema, try creating > a table for your model (Inventory) > > So I read log/development.log, and it contains this: > > Error: Table ''rails_development.inventories'' doesn''t exist > > The system is inexplicably pluralizing my table name. Am I using the > system wrong, or is this a false "feature"? > > Can I fix it by adding a view called ''inventories''? Or must I rename the > table? > > And how, in general, can Rails present data views that don''t have the > same shape as the target database schema? Such schemas should be > normalized beyond recognition...These might come in handy... Rails HowTo: Pluralizing http://www.slash7.com/articles/2005/11/17/rails-howto-pluralizing Riding Rails: 10 Reasons Rails Does Pluralization http://weblog.rubyonrails.com/2005/08/25/10-reasons-rails-does-pluralization/ http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000880
Hi Philip, The table/model naming isn''t a "false" feature, but a feature :) You don''t have to create a view or rename the table, though your life will be made easier if your table names are pluralized. If you want to use a table name that Rails doesn''t expect, you can use "set_table_name ''inventory''" in your model class. And yes, you can have models which correspond to views - I''m not sure what operations you can perform, but I know you can at least read rows from the view. On Tuesday 15 August 2006 07:51, Phlip wrote:> Railers: > > Greetings from the low end of the learning curve. I have installed all > the prerequisites on Win32, including a lite MySQL database with a > table in it called Inventory. > > Then I run this command line... > > ruby script/generate ajax_scaffold Inventory > > ...and I get this error message: > > error Before updating scaffolding from new DB schema, try creating > a table for your model (Inventory) > > So I read log/development.log, and it contains this: > > Error: Table ''rails_development.inventories'' doesn''t exist > > The system is inexplicably pluralizing my table name. Am I using the > system wrong, or is this a false "feature"? > > Can I fix it by adding a view called ''inventories''? Or must I rename the > table? > > And how, in general, can Rails present data views that don''t have the > same shape as the target database schema? Such schemas should be > normalized beyond recognition...
Philip Hallstrom wrote:> Riding Rails: 10 Reasons Rails Does Pluralization > http://weblog.rubyonrails.com/2005/08/25/10-reasons-rails-does-pluralization/And, uh, adding a single line to the default Rails page would have ... prevented the need for such a clever page? And its attendant FAQ? -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!
Daniel Higginbotham wrote:> The table/model naming isn''t a "false" feature, but a feature :) You don''t > have to create a view or rename the table, though your life will be made > easier if your table names are pluralized. If you want to use a table name > that Rails doesn''t expect, you can use "set_table_name ''inventory''" in your > model class.No I can''t. The model class doesn''t exist until I run generate, which won''t finish until I pluralize the table name. Another reason why you will continue to field this FAQ is because, up until that error message (AND until dumping the log to see what the real problem was), there''s simply no way for the initiate to guess they are on-track. I couldn''t tell if I screwed up here, or long before, and I couldn''t tell if I was at the head of the error cascade. So even >I< had to ask, despite I have been using Model-View-Controller, and writing Web servers from scratch, since before Ruby existed... -- Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!
Phlip wrote:> Daniel Higginbotham wrote: > >> The table/model naming isn''t a "false" feature, but a feature :) You >> don''t >> have to create a view or rename the table, though your life will be made >> easier if your table names are pluralized. If you want to use a table >> name >> that Rails doesn''t expect, you can use "set_table_name ''inventory''" >> in your >> model class. > > No I can''t. The model class doesn''t exist until I run generate, which > won''t finish until I pluralize the table name. > > Another reason why you will continue to field this FAQ is because, up > until that error message (AND until dumping the log to see what the > real problem was), there''s simply no way for the initiate to guess > they are on-track. I couldn''t tell if I screwed up here, or long > before, and I couldn''t tell if I was at the head of the error cascade. > So even >I< had to ask, despite I have been using > Model-View-Controller, and writing Web servers from scratch, since > before Ruby existed... >I may be missing something here (and a search to see your earlier post reveals that you were using AjaxScaffold) but as I understand it, you can always create a model without creating the table name in plural. In the way I know it: dir>ruby script\generate model Inventory * this will create the model ''inventory'' (app\models\inventory.rb) and a migration that will db\migrate\xxx_create_inventory (i think) - this file is the one that will actually update the database to create the specific table and its fields. * you should be able to go to app\models\inventory.rb and add set_table_name ''inventory'' to make it all work. I may be wrong, but that is my understanding. It seems that it ''may'' be a restriction in AjaxScaffold (or perhaps it will work fine after the model is defined to use the table ''inventory'') but it''s certainly not a problem with the way Rails works. Cheers Mohit.
@Phlip: The workflow that should be observed for creating a Rails application is 0. Create a Rails app (of course) 1. start with a blank database (no tables0 2. ruby script/generate model InventoryItems 3. edit the file db/migrate/001_create_inventory_items.rb 4. Define your table definition using this file. 5. run ''rake migrate'' to build the table in your database. 6. Test with console ruby script/console @inventory_item = InventoryItem.new @inventory_item.name = "widget" @inventory_item.description = "some thing that does some stuff" @inventory_item.save @inventory_item = InventoryItem.find :first @inventory_item.name 7. Write unit tests using something similar to the console entries above. 8. Edit your app/models/inventory_item.rb file and do any validations, etc 9. Run your tests again. 10 ** OPTIONAL ** ruby script/generate scaffold InventoryItem inventory 11. ruby script/server and test in the browser. Why InventoryItem? Because I just don''t like using inventories, and it makes more sence to me later when I say store :has_many :inventory_items -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060815/c877bed3/attachment.html