I am new to Ruby and RubyOnRails, and am trying to learn textbooks.
The specific book that I am referring to at this point in time is
“Beginning Ruby on Rails E-Commerce” published by Apress and written by
Christian Hellsten and Jarkko L…
The book uses Ubuntu Linux. I am also using Ubuntu 6.06 Dapper. I
have installed MySQL, ruby, gems, rubyonrails as instructed in the book
and everything has installed correctly (or so it seems to me).
I am upto chapter 2 where the authors show you how to create a simple
authors table with first_name and last_name fields using migrations.
Here is the migration script contained in a file called
001_create_authors.rb stored in the ~/projects/emporium/db/migrate
directory:
class CreateAuthors < ActiveRecord::Migration
def self.up
create_table :authors do |t|
t.column :first_name, :string
t.column :last_name, :string
end
end
def self.down
drop_table :authors
end
end
When I try to run it by using the following command:
rake db/migrate
I get one line output as follows:
(in /home/bruparel/projects/emporium)
And nothing else. Unlike the book which shows the result of migration
script running.
I am trying to figure out why nothing is happening. The desired
outcome is off-course that a table called authors gets created in the
emporium_development database (I am using MySQL as instructed in the
book and to keep the things as simple as possible).
Here is the database yaml file:
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:
There is no gem for Windows. Install mysql.so from RubyForApache.
http://rubyforge.org/projects/rubyforapache
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: emporium_development
username: emporium
password: hacked
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: emporium_test
username: emporium
password: hacked
host: localhost
production:
adapter: mysql
database: emporium_production
username: root
password:
host: localhost
Trouble is: I have checked the log file and nothing is written there
concerning anything to do with the database. I have MySql running
fine, here is the result to executing the linux
ps -ef | grep mysql
root 7638 1 0 10:41 pts/0 00:00:00 /bin/sh
/usr/bin/mysqld_safe
mysql 7702 7638 0 10:41 pts/0 00:00:00 /usr/sbin/mysqld
–basedir=/usr --datadir=/var/lib/mysql --user=mysql
–pid-file=/var/run/mysqld/mysqld.pid --skip-locking --port=3306
–socket=/var/run/mysqld/mysqld.sock
root 7703 7638 0 10:41 pts/0 00:00:00 logger -p daemon.err -t
mysqld_safe -i -t mysqld
bruparel 9101 9068 0 11:27 pts/1 00:00:00 mysql -u root -p
bruparel 24756 9254 0 21:52 pts/2 00:00:00 grep mysql
This shows that my server is running. Further I can also connect to it
using mysql command line client. I created both emporium_development
and emporium_test databases as the book asks us to. I can see that
using mysql client fine.
I am not sure why RubyOnRails is not connecting to Mysql database and
create the authors table. I tried changing the user name and password
values in database.yml file to see if an error is logged or displayed
somewhere, no luck. It is quite likely that I don’t know where to
look.
The thing that I would appreciate some help with is how to go about
troubleshooting these types of problems.
Thanks in advance.
Bharat