Scaffold command, how and what may be wrong?

hi everyone. I am learning RoR and just recently purchase the agile wed
dev on rails. i am still at the beginning of the book trying to create
the scaffold for the depot_development database. Everytime i run the
generate scaffold products admin, i recieve the “before building the
scaffold, try to create a table for model products” etc…

a few questions:

  1. How does ruby know that Products table is located in the
    Depot_Development DB? What if i have the same name Table Products is in
    another Database? I have a feeling that for some reason it cant see the
    products table.

  2. Is product table in the scaffold command case sensitive? In the book,
    the author defines the table in mysql with a ‘s’ in Products, but when
    he runs the scaffold command, its singular Product.

  3. after browsing a lot in google, ive read that one needs to do this,
    “gem install mysql”. why? if i already have mysql installed? does GEM
    make ruby use mysql, hence the need for “gem install mysql”. i was
    getting plenty of errors trying to run the gem command, so out of
    frustration, i uninstalled and reinstalled everything, so now i can run
    the “gem install mysql”

i dont know what else i can do. i will however try to change local host
to 127.0…

i am running ubuntu 5.10.

koloa none wrote:

hi everyone. I am learning RoR and just recently purchase the agile wed
dev on rails. i am still at the beginning of the book trying to create
the scaffold for the depot_development database. Everytime i run the
generate scaffold products admin, i recieve the “before building the
scaffold, try to create a table for model products” etc…

If you haven’t turned off the pluralizing of the Inflector you want the
following:

  1. Name your table products.
  2. script/generate scaffold Product
  1. How does ruby know that Products table is located in the
    Depot_Development DB? What if i have the same name Table Products is in
    another Database? I have a feeling that for some reason it cant see the
    products table.

You configure your databases usage in config/database.yml.

  1. Is product table in the scaffold command case sensitive? In the book,
    the author defines the table in mysql with a ‘s’ in Products, but when
    he runs the scaffold command, its singular Product.

Here’s what the scaffold generator tells me about it’s command line
parameters:

Usage: script/generate scaffold ModelName [ControllerName] [action, …]

It takes a modelname as the first parameter, not a table name. Models
are usually named in singular with a capital starting letter, which is
why it’s singular Product.

  1. after browsing a lot in google, ive read that one needs to do this,
    “gem install mysql”. why? if i already have mysql installed? does GEM
    make ruby use mysql, hence the need for “gem install mysql”.

The gem system is a way of packaging Ruby libraries. It doesn’t make
ruby use mysql. The mysql gem does however, which is why you need it.

koloa none wrote:

a few questions:

  1. How does ruby know that Products table is located in the
    Depot_Development DB? What if i have the same name Table Products is in
    another Database? I have a feeling that for some reason it cant see the
    products table.
    It’s defined in the config/database.yml file. The development database
    should be set up under the development section.
  1. Is product table in the scaffold command case sensitive?
    That will, I think, depend on your database, and possibly your file
    system. PostgreSQL is case insensitive, MySQL is case sensitive on
    Linux (as a rule).

In the book,
the author defines the table in mysql with a ‘s’ in Products, but when
he runs the scaffold command, its singular Product.
That’s because the parameter to the scaffold command isn’t actually a
table name, but the name of the class that will wrap access to the
database table. Table names are (by convention) the plural of whatever
a row represents, class names are singular.

  1. after browsing a lot in google, ive read that one needs to do this,
    “gem install mysql”. why? if i already have mysql installed? does GEM
    make ruby use mysql, hence the need for “gem install mysql”. i was
    getting plenty of errors trying to run the gem command, so out of
    frustration, i uninstalled and reinstalled everything, so now i can run
    the “gem install mysql”
    Gem is the ruby package management system. ‘gem install mysql’ doesn’t
    tell it to reinstall MySQL, but instead to install the ruby libraries
    necessary for rails to talk to MySQL. They’re probably failing because
    it’s trying to build native extensions, and you don’t have something it
    needs installed. What errors were you seeing?

i dont know what else i can do. i will however try to change local host
to 127.0…

i am running ubuntu 5.10.
Do you have build-essential installed? I installed 5.10 over the
weekend, following these instructions:

) Make sure you have universe and multiverse enabled and select the
rails
) package in synaptic. This will install all the correct dependencies.
) De-select rails and install the ruby packages.

and it seems fine so far. I thought I had a ruby version problem, but
it turns out that Ubuntu ruby is not the version it thinks it is.

I just started with the book, too. I see others have answered you, but
since I already started, I thought maybe the page references would help.

Everytime i run the
generate scaffold products admin, i recieve the “before building the
scaffold, try to create a table for model products” etc…

You do need to create the database as products . . . see below.

a few questions:

  1. How does ruby know that Products table is located in the
    Depot_Development DB? What if i have the same name Table Products is in
    another Database? I have a feeling that for some reason it cant see the
    products table.

It knows because you told it (or should have) in config/database.yml (p
56
in the 3rd printing).

  1. Is product table in the scaffold command case sensitive? In the book,
    the author defines the table in mysql with a ‘s’ in Products, but when
    he runs the scaffold command, its singular Product.

There are conventions for naming, covered in more detail on page 191 in
the sidebar headed “Why Plural for Tables?” Basically it makes it easier
to talk to clients.

  1. after browsing a lot in google, ive read that one needs to do this,
    “gem install mysql”. why? if i already have mysql installed? does GEM
    make ruby use mysql, hence the need for “gem install mysql”. i was
    getting plenty of errors trying to run the gem command, so out of
    frustration, i uninstalled and reinstalled everything, so now i can run
    the “gem install mysql”

I run OSX and I didn’t need to do this (so far, but then, I’m stuck at
page 73 and OSX ships with ruby). I understand that what’s being
installed
by “gems install mysql” is the mysql database adaptor for ruby. I might
be
wrong about that, but I’m pretty certain it’s not mysql itself.

Good luck.

Hi THANKS all for responding. I hope ican resolve this problem tonight
since this will be my 3rd day trying to figure it out!..well at least
im learning how to use linux. lol…

Yes, i created the products table, but the table is in the
Depot_development database.

how does ruby know that I want to create a scaffold for the products
table in the depot_development database and not for example a table
named products in Some other database?

in my database.yml, i have 3 sections for each database, but no info
about any tables. does there need to be any ‘include’ statements or
‘require’ at the beginning of the file?

thanks again!

Melissa Anderson wrote:

I just started with the book, too. I see others have answered you, but
since I already started, I thought maybe the page references would help.

Everytime i run the
generate scaffold products admin, i recieve the “before building the
scaffold, try to create a table for model products” etc…

You do need to create the database as products . . . see below.

a few questions:

  1. How does ruby know that Products table is located in the
    Depot_Development DB? What if i have the same name Table Products is in
    another Database? I have a feeling that for some reason it cant see the
    products table.

It knows because you told it (or should have) in config/database.yml (p
56
in the 3rd printing).

  1. Is product table in the scaffold command case sensitive? In the book,
    the author defines the table in mysql with a ‘s’ in Products, but when
    he runs the scaffold command, its singular Product.

There are conventions for naming, covered in more detail on page 191 in
the sidebar headed “Why Plural for Tables?” Basically it makes it easier
to talk to clients.

  1. after browsing a lot in google, ive read that one needs to do this,
    “gem install mysql”. why? if i already have mysql installed? does GEM
    make ruby use mysql, hence the need for “gem install mysql”. i was
    getting plenty of errors trying to run the gem command, so out of
    frustration, i uninstalled and reinstalled everything, so now i can run
    the “gem install mysql”

I run OSX and I didn’t need to do this (so far, but then, I’m stuck at
page 73 and OSX ships with ruby). I understand that what’s being
installed
by “gems install mysql” is the mysql database adaptor for ruby. I might
be
wrong about that, but I’m pretty certain it’s not mysql itself.

Good luck.

koloa none wrote:

a few questions:

  1. How does ruby know that Products table is located in the
    Depot_Development DB? What if i have the same name Table Products is in
    another Database? I have a feeling that for some reason it cant see the
    products table.

theres a database.yaml file that points you rails application to the
database it should use.

  1. Is product table in the scaffold command case sensitive? In the book,
    the author defines the table in mysql with a ‘s’ in Products, but when
    he runs the scaffold command, its singular Product.

thats right.
Scaffold also generates the models, views and controllers and the model
is singular

  1. after browsing a lot in google, ive read that one needs to do this,
    “gem install mysql”. why? if i already have mysql installed? does GEM
    make ruby use mysql, hence the need for “gem install mysql”.

I think there are native ruby MySQL API’s but read theres a better one
written in C++ which is faster for Ruby/Rails to use. I saw lots of
instructions to do that, but couldn’t get it to work.

I’d try geeting MySQl working first, see if you can connect through the
coomand line, GUI or PHPMyAdmin whichever you prefer. The check your
database.yaml is correctly point to the right host, db, password etc

_tony

any ideas on what/how to debug?

i am home now and tried changing localhost to 127.0.01 but got an error
saying localhost can not connect to localhost.localdomain, so i changed
it back. i verified that product table is where it should be in depot
development.

when i type “ruby script/generate scaffold product admin” i get this
error

" error Before updating scaffolding from new DB schema, try creating a
table for your model (Product)"

!!!

Connect to depot_development via the mysql monitor, run the show tables
command . . . the table name must be products all lower case.

On Tue, 2006-02-28 at 23:31 +0100, bbqbaker wrote:

i am home now and tried changing localhost to 127.0.01 but got an error
saying localhost can not connect to localhost.localdomain, so i changed
it back. i verified that product table is where it should be in depot
development.

when i type “ruby script/generate scaffold product admin” i get this
error

" error Before updating scaffolding from new DB schema, try creating a
table for your model (Product)"


localhost (localhost.localdomain) is 127.0.0.1

note the difference from what you typed but you may have had a typo to
the list - the nature of hosts file is that it is not forgiving in
nature.

As for scaffolding…as Melissa stated, the table must exist.

In mysql, you will need a database named - as I recall,
depot_development and a table in this database called ‘products’

Craig

MELISSA ANDERSON YOU ARE THE BEST!

oh my, after playing around, deleting stuff, creating stuff, searching a
more on google, i works!..

after i deleted and created a table, i made sure it was all lower case.
afterwards i got a new error message about write protection…well i did
more searching on google and found that another person had the similiar
problem and just did a simple sudo gem install rails. what ever happened
between a few days ago to today, i must of messed things up. after i ran
the command, scaffold works!!!

thank you guys soo much and craig from the other noob thread i started.
i hope now i can help other newcommers since i may be the official
scaffold domain expert debugger guy!

Melissa Anderson wrote:

Connect to depot_development via the mysql monitor, run the show tables
command . . . the table name must be products all lower case.