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:
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…
error Before updating scaffolding from new DB schema, try creating
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…
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.
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.
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…
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.