How do I create a table for my model?

I’m not sure what is meant by “create a table for the model” because the
database has a table…they mean a different table?

[thufir@localhost dummy]$
[thufir@localhost dummy]$
[thufir@localhost dummy]$ ruby script/generate scaffold dummy
exists app/controllers/
exists app/helpers/
exists app/views/dummies
exists app/views/layouts/
exists test/functional/
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
identical app/models/dummy.rb
identical test/unit/dummy_test.rb
identical test/fixtures/dummies.yml
error Before updating scaffolding from new DB schema, try
creating a table for your model (Dummy)
[thufir@localhost dummy]$ ll
total 116
drwxrwxr-x 6 thufir thufir 4096 May 13 04:15 app
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 components
drwxrwxr-x 3 thufir thufir 4096 May 13 05:11 config
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 db
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 doc
drwxrwxr-x 3 thufir thufir 4096 May 13 04:15 lib
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 log
drwxrwxr-x 5 thufir thufir 4096 May 13 04:15 public
-rw-rw-r-- 1 thufir thufir 307 May 13 04:15 Rakefile
-rw-rw-r-- 1 thufir thufir 8001 May 13 04:15 README
drwxrwxr-x 4 thufir thufir 4096 May 13 04:15 script
drwxrwxr-x 7 thufir thufir 4096 May 13 04:15 test
drwxrwxr-x 6 thufir thufir 4096 May 13 04:15 tmp
drwxrwxr-x 3 thufir thufir 4096 May 13 04:15 vendor
[thufir@localhost dummy]$
[thufir@localhost dummy]$
[thufir@localhost dummy]$ cat config/database.yml

MySQL (default setup). Versions 4.1 and 5.0 are recommended.

Install the MySQL driver:

gem install mysql

On MacOS X:

gem install mysql – --include=/usr/local/lib

On Windows:

gem install mysql

Choose the win32 build.

Install MySQL and put its /bin directory on your path.

And be sure to use new-style password hashing:

http://dev.mysql.com/doc/refman/5.0/en/old-client.html

development:
adapter: mysql
database: dummy_development
username: feeds
password: password
socket: /var/lib/mysql/mysql.sock

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: dummy_test
username: feeds
password: password
socket: /var/lib/mysql/mysql.sock

production:
adapter: mysql
database: dummy_production
username: feeds
password: password
socket: /var/lib/mysql/mysql.sock
[thufir@localhost dummy]$
[thufir@localhost dummy]$
[thufir@localhost dummy]$ mysql -u feeds -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 37 to server version: 5.0.27

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql>
mysql> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
| dummy |
| dummy_development |
| feeds |
| mysql |
| test |
±-------------------+
6 rows in set (0.00 sec)

mysql> use dummy;
Reading table information for completion of table and column
names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> describe dummy;
ERROR 1146 (42S02): Table ‘dummy.dummy’ doesn’t exist
mysql> show tables;
±----------------+
| Tables_in_dummy |
±----------------+
| px_feeds |
±----------------+
1 row in set (0.00 sec)

mysql> describe px_feeds;
±------------±-------------±-----±----±--------
±---------------+
| Field | Type | Null | Key | Default |
Extra |
±------------±-------------±-----±----±--------
±---------------+
| id | int(11) | NO | PRI | NULL |
auto_increment |
| url | varchar(250) | NO | |
| |
| title | varchar(250) | NO | |
| |
| link | varchar(250) | YES | | NULL
| |
| description | varchar(250) | YES | | NULL
| |
±------------±-------------±-----±----±--------
±---------------+
5 rows in set (0.01 sec)

mysql>
mysql> quit
Bye
[thufir@localhost dummy]$
[thufir@localhost dummy]$
[thufir@localhost dummy]$ cat /etc/fedora-release
Fedora Core release 6 (Zod)
[thufir@localhost dummy]$
[thufir@localhost dummy]$ date
Mon May 14 16:46:54 BST 2007
[thufir@localhost dummy]$
[thufir@localhost dummy]$

thanks,

Thufir

On May 14, 2007, at 11:49 AM, Thufir wrote:

I’m not sure what is meant by “create a table for the model”
because the
database has a table…they mean a different table?

From your output it looks like you have a database named ‘dummy’
containing a single table named ‘px_feeds’. The scaffold generator
can automatically create a PxFeed model based on the px_feeds table,
but you’re (implicitly) telling it to look for a ‘dummies’ table to
create a Dummy model and DummiesController controller (‘dummy’ ->
‘dummies’, assuming this falls under the general pluralization rules).

-faisal

Rails assumes, that the table for a model called “dummy” is called
“dummies”, the table for a “user” model would be “users” etc. - unless
you’ve configured Rails differently. That’s one of Rails’ main
priciples, convention over configuration. I’d recommend a book called
“Agile web development with Rails” - the first part walks you through
the development of a simple shop app, which will address 90% of the
problems you’ll come across eventually, the second is a great
reference when you start building your own apps (and it also includes
the basics of Ruby, so don’t worry about that). It’s definitely worth
it - and look for the 2nd edition.
http://pragmaticprogrammer.com/titles/rails

On May 14, 9:01 am, Faisal N Jawdat [email protected] wrote:
[…]

From your output it looks like you have a database named ‘dummy’
containing a single table named ‘px_feeds’. The scaffold generator
can automatically create a PxFeed model based on the px_feeds table,
but you’re (implicitly) telling it to look for a ‘dummies’ table to
create a Dummy model and DummiesController controller (‘dummy’ →
‘dummies’, assuming this falls under the general pluralization rules).

-faisal

Aha, thanks. Long term I’ll have to muck with the the configuration
because the feed-on-feeds database is setup how it’s setup, ruby will
have to work around it :frowning:

-Thufir

On May 14, 8:30 pm, tjanson [email protected] wrote:

Rails assumes, that the table for a model called “dummy” is called
“dummies”, the table for a “user” model would be “users” etc. - unless
you’ve configured Rails differently.
[…]

Have I not done so?

[thufir@localhost dummy]$
[thufir@localhost dummy]$ ruby script/generate scaffold dummy
exists app/controllers/
exists app/helpers/
exists app/views/dummies
exists app/views/layouts/
exists test/functional/
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
identical app/models/dummy.rb
identical test/unit/dummy_test.rb
identical test/fixtures/dummies.yml
error Before updating scaffolding from new DB schema, try
creating a table for your model (Dummy)
[thufir@localhost dummy]$
[thufir@localhost dummy]$ pwd
/home/thufir/dummy
[thufir@localhost dummy]$ ll
total 116
drwxrwxr-x 6 thufir thufir 4096 May 13 04:15 app
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 components
drwxrwxr-x 3 thufir thufir 4096 May 13 05:11 config
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 db
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 doc
drwxrwxr-x 3 thufir thufir 4096 May 13 04:15 lib
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 log
drwxrwxr-x 5 thufir thufir 4096 May 13 04:15 public
-rw-rw-r-- 1 thufir thufir 307 May 13 04:15 Rakefile
-rw-rw-r-- 1 thufir thufir 8001 May 13 04:15 README
drwxrwxr-x 4 thufir thufir 4096 May 13 04:15 script
drwxrwxr-x 7 thufir thufir 4096 May 13 04:15 test
drwxrwxr-x 6 thufir thufir 4096 May 13 04:15 tmp
drwxrwxr-x 3 thufir thufir 4096 May 13 04:15 vendor
[thufir@localhost dummy]$
[thufir@localhost dummy]$ mysql -u feeds -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 32 to server version: 5.0.27

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql>
mysql> use dummy;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
±----------------+
| Tables_in_dummy |
±----------------+
| dummies |
±----------------+
1 row in set (0.00 sec)

mysql> quit
Bye
[thufir@localhost dummy]$
[thufir@localhost dummy]$ cat config/database.yml

MySQL (default setup). Versions 4.1 and 5.0 are recommended.

Install the MySQL driver:

gem install mysql

On MacOS X:

gem install mysql – --include=/usr/local/lib

On Windows:

gem install mysql

Choose the win32 build.

Install MySQL and put its /bin directory on your path.

And be sure to use new-style password hashing:

http://dev.mysql.com/doc/refman/5.0/en/old-client.html

development:
adapter: mysql
database: dummy_development
username: feeds
password: password
socket: /var/lib/mysql/mysql.sock

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: dummy_test
username: feeds
password: password
socket: /var/lib/mysql/mysql.sock

production:
adapter: mysql
database: dummy_production
username: feeds
password: password
socket: /var/lib/mysql/mysql.sock
[thufir@localhost dummy]$
[thufir@localhost dummy]$ cat /etc/fedora-release
Fedora Core release 6 (Zod)
[thufir@localhost dummy]$
[thufir@localhost dummy]$ date
Wed May 16 02:19:51 BST 2007
[thufir@localhost dummy]$

thanks,

Thufir

It looks like your database is called “dummy”,

mysql> use dummy;

but your YAML file (and Rails convention) has “dummy_development”,
etc.

development:
adapter: mysql
database: dummy_development

Is that your problem? (Sorry, didn’t see or pay attention to your
initial post)

-Rob

On May 15, 2007, at 9:22 PM, Thufir wrote:

  exists    test/unit/

total 116
drwxrwxr-x 4 thufir thufir 4096 May 13 04:15 script

| dummies |

gem install mysql

adapter: mysql
database: dummy_test
[thufir@localhost dummy]$
Thufir
Rob B. http://agileconsultingllc.com
[email protected]

On May 16, 3:38 am, Rob B. [email protected]
wrote:

It looks like your database is called “dummy”,

mysql> use dummy;

but your YAML file (and Rails convention) has “dummy_development”,
etc.
[…]

This I’m unclear on. The database should be called dummy or
dummy_development ? change the YAML to match the database or the
database to match the YAML? If the mountain won’t come to mohammed,
then…

I was thinking that ruby would automagically figure out the
*_development in keeping with its automagically figuring out dummy and
its plural dummies.

-Thufir

thanks, one step closer :slight_smile:

now I’m looking into how to display a “SELECT * FROM dummies” query.

[thufir@localhost dummy]$
[thufir@localhost dummy]$
[thufir@localhost dummy]$ pwd
/home/thufir/dummy
[thufir@localhost dummy]$
[thufir@localhost dummy]$ ll
total 116
drwxrwxr-x 6 thufir thufir 4096 May 13 04:15 app
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 components
drwxrwxr-x 3 thufir thufir 4096 May 16 06:06 config
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 db
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 doc
drwxrwxr-x 3 thufir thufir 4096 May 13 04:15 lib
drwxrwxr-x 2 thufir thufir 4096 May 13 04:15 log
drwxrwxr-x 5 thufir thufir 4096 May 13 04:15 public
-rw-rw-r-- 1 thufir thufir 307 May 13 04:15 Rakefile
-rw-rw-r-- 1 thufir thufir 8001 May 13 04:15 README
drwxrwxr-x 4 thufir thufir 4096 May 13 04:15 script
drwxrwxr-x 7 thufir thufir 4096 May 13 04:15 test
drwxrwxr-x 6 thufir thufir 4096 May 13 04:15 tmp
drwxrwxr-x 3 thufir thufir 4096 May 13 04:15 vendor
[thufir@localhost dummy]$
[thufir@localhost dummy]$ cat config/database.yml

MySQL (default setup). Versions 4.1 and 5.0 are recommended.

Install the MySQL driver:

gem install mysql

On MacOS X:

gem install mysql – --include=/usr/local/lib

On Windows:

gem install mysql

Choose the win32 build.

Install MySQL and put its /bin directory on your path.

And be sure to use new-style password hashing:

http://dev.mysql.com/doc/refman/5.0/en/old-client.html

development:
adapter: mysql
database: dummy
username: feeds
password: password
socket: /var/lib/mysql/mysql.sock

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: dummy
username: feeds
password: password
socket: /var/lib/mysql/mysql.sock

production:
adapter: mysql
database: dummy
username: feeds
password: password
socket: /var/lib/mysql/mysql.sock
[thufir@localhost dummy]$
[thufir@localhost dummy]$ ruby script/generate scaffold dummy
exists app/controllers/
exists app/helpers/
exists app/views/dummies
exists app/views/layouts/
exists test/functional/
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
identical app/models/dummy.rb
identical test/unit/dummy_test.rb
identical test/fixtures/dummies.yml
identical app/views/dummies/_form.rhtml
identical app/views/dummies/list.rhtml
identical app/views/dummies/show.rhtml
identical app/views/dummies/new.rhtml
identical app/views/dummies/edit.rhtml
identical app/controllers/dummies_controller.rb
identical test/functional/dummies_controller_test.rb
identical app/helpers/dummies_helper.rb
identical app/views/layouts/dummies.rhtml
identical public/stylesheets/scaffold.css
[thufir@localhost dummy]$
[thufir@localhost dummy]$ ruby script/server
=> Booting WEBrick…
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2007-05-16 06:13:09] INFO WEBrick 1.3.1
[2007-05-16 06:13:09] INFO ruby 1.8.5 (2007-03-13) [i386-linux]
[2007-05-16 06:13:09] INFO WEBrick::HTTPServer#start: pid=3786
port=3000
127.0.0.1 - - [16/May/2007:06:13:15 BST] “GET / HTTP/1.1” 304 0

  • → /
    127.0.0.1 - - [16/May/2007:06:13:16 BST] “GET /javascripts/
    prototype.js HTTP/1.1” 304 0
    http://localhost:3000/ → /javascripts/prototype.js
    127.0.0.1 - - [16/May/2007:06:13:16 BST] “GET /javascripts/effects.js
    HTTP/1.1” 304 0
    http://localhost:3000/ → /javascripts/effects.js
    127.0.0.1 - - [16/May/2007:06:13:16 BST] “GET /images/rails.png HTTP/
    1.1” 304 0
    http://localhost:3000/ → /images/rails.png
    [2007-05-16 06:13:23] INFO going to shutdown …
    [2007-05-16 06:13:23] INFO WEBrick::HTTPServer#start done.
    [thufir@localhost dummy]$
    [thufir@localhost dummy]$ date
    Wed May 16 06:13:26 BST 2007
    [thufir@localhost dummy]$
    [thufir@localhost dummy]$

thanks,

Thufir