Railsでデモを作れぇ!

Webアプリの見積もりが来て、イメージを固めるために、Railsでデモを作ろう!
って、そんな余裕があるのかぁ?

とりあえず、castleに置いてあるRailsの環境を使ってみる。

$ mkdir railsTest
$ cd railsTest
$ rails accident
$ cd accident
$ vi config/database.yml

でdatabase.ymlの編集。
ここで、socket: /var/lib/mysql/mysql.sock
を追加しないと、ソケットファイルが見つからないと言われる

で、WebminからMySqlにaccident_production,accident_test,accident_developmentのdbを作成
userとしてrailsを作成して、権限を設定。
$ rake migrate
すると、
Mysql::Error: Lost connection to MySQL server during query: SELECT version FROM schema_info
が出る。
ググッてみると、権限の問題とかMySQLをアップグレードした問題がヒットする。
rootに変更してみたけど、解消しない。

http://blog.s21g.com/articles/18

http://weblog.greenpeace.org/it/2006/04/mysql_gem_woes_staging_instanc.html
の内容を元に、

$ gem install mysql
$ su -
# cd /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7
# vi extconf.rb
# ruby extconf.rb
checking for main() in -lmysqlclient... no
checking for mysql_ssl_set()... no
checking for mysql.h... no
checking for mysql/mysql.h... yes
creating Makefile
# ruby extconf.rb --with-mysql-lib=/usr/lib/mysql
checking for main() in -lmysqlclient... no
checking for mysql_ssl_set()... no
checking for mysql.h... no
checking for mysql/mysql.h... yes
creating Makefile
# make install
gcc -I. -I. -I/usr/local/lib/ruby/1.8/x86_64-linux -I. -DHAVE_MYSQL_MYSQL_H -I/usr/local/include -fPIC -g -O2 -c mysql.c
gcc -shared -L'/usr/lib/mysql' -Wl,-R'/usr/lib/mysql' -L'/usr/local/lib' -Wl,-R'/usr/local/lib' -L'/usr/local/lib' -Wl,-R'/usr/local/lib' -o mysql.so mysql.o -ldl -lcrypt -lm -lc
/usr/bin/install -c -m 0755 mysql.so /usr/local/lib/ruby/site_ruby/1.8/x86_64-linux
# exit
% rake migrate
(in /home/kkijiya/RailsTest/accident)
/usr/local/bin/ruby: symbol lookup error: /usr/local/lib/ruby/site_ruby/1.8/x86_64-linux/mysql.so: undefined symbol: mysql_init

どっかーん!!
ちなみに、ruby extconf.rbを実行すると、mysql.soが作成されて、make installするとそれが/usr/local/lib/ruby/site_ruby/1.8/x86_64-linux
にコピーされているようだ。
って、事は、事前にコピッて置かなかった私の負けね。(T-T)
もう一度、インストールのし直しかぁ?
====================================================================================================
ここで詰まっているよりも(何せ64bitなのよ)と、VMwareのCentOS4.4環境にスイッチする

でも、rubyすら入っていないので、
# yum install rubyして

Installing:
ruby i386 1.8.1-7.EL4.8.1 update 156 k
ruby-devel i386 1.8.1-7.EL4.8.1 update 433 k
ruby-docs i386 1.8.1-7.EL4.8.1 update 1.2 M
ruby-libs i386 1.8.1-7.EL4.8.1 update 1.5 M
ruby-mode i386 1.8.1-7.EL4.8.1 update 44 k
ruby-tcltk i386 1.8.1-7.EL4.8.1 update 524 k

をインストール。
wget http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz
でgemsを持ってきて、

$ tar -zxvf rubygems-1.0.1.tgz
$ cd rubygems-1.0.1
$ ruby setup.rb

でエラー
.... gemsって、1.8.2以降?
うーん、どこかにバージョンの依存関係が纏めてあっても良さそうな。探しても見あたらない。
一旦yumruby関連をアンインストール
wget http://core.ring.gr.jp/archives/lang/ruby/1.8/ruby-1.8.6-p111.tar.gz
rubyを持ってきて、

# tar -zxvf ruby-1.8.6-p111.tar.gz
# cd ruby-1.8.6-p111
# ./configure
# make;make install

で、インストール
改めて、gemsに移動して
# ruby setup.rbを実行すると、rubyが見つからないと言う。
# export PATH=$PATH:/usr/local/bin
でパスを通してやると、それらしく動いたけど最後に

install -c -m 0755 /tmp/update_rubygems /usr/local/bin/update_rubygems
rm /tmp/update_rubygems
cp gem /tmp/gem
install -c -m 0755 /tmp/gem /usr/local/bin/gem
rm /tmp/gem
Removing old RubyGems RDoc and ri...
Installing rubygems-1.0.1 ri into /usr/local/lib/ruby/gems/1.8/doc/rubygems-1.0.1/ri...
Installing rubygems-1.0.1 rdoc into /usr/local/lib/ruby/gems/1.8/doc/rubygems-1.0.1/rdoc...
As of RubyGems 0.8.0, library stubs are no longer needed.
Searching $LOAD_PATH for stubs to optionally delete (may take a while)...
...done.
No library stubs found.

と言う。あってるの?
http://d.hatena.ne.jp/troopergreen/searchdiary?word=Ruby
によると、良いらしいので次に進む。
# gem install rails --include-dependencies
これはOK

$ mkdir RailsTest
$ cd RailsTest
$ rails accident
$ cd accident
$ vi config/database.yml

で編集しようとしたら、adapter: sqlite3になっているぞ。

mysqlを起動しようとしたら、mysqlが入っていないので

# yum install mysql*

webminから起動してみて起動OK
ライドオンRailによると、/etc/my.confに
default-character-set=utf8を設定するらしい。
一旦mysqldを止めて、my.confを編集して再起動したが、エラーで起動できなくなった。
my.confを戻しても駄目、
/var/lib/mysql配下を削除して、webminから起動してみても駄目
yum removeで一旦削除して、再インストールしても駄目
削除した状態で、再起動して再インストールでも駄目

http://bbs.fedora.jp/read.php?FID=8&TID=3772
を参考に

# rm -fr /var/lib/mysql/*
# mysql_install_db

を実施すると、以下

Installing all prepared tables
Fill help tables

To start mysqld at boot time you have to copy support-files/mysql.server
to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h cent44 password 'new-password'
See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
cd sql-bench ; perl run-all-tests

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com

で、

# service mysqld start
MySQL を起動中: [ OK ]

よかった。起動できた。

service mysqld stop
MySQL を停止中: [ OK ]

それでは、改めてmy.cnfを修正
今度はOK

# service mysqld start
MySQL を起動中: [ OK ]

さて、どこまで行ってたんだっけ?
そうそう、database.ymlの編集で、sqlite3だったのね。

# gem install mysql

して、やり直しても同じ。sqlite3になる。
で、ググッて見るとrailsの2.0からはデフォルトがsqlite3になったとか。

# rails -d mysql accident

とすると、ちゃんとmysqlになっているし、encodeもsocketも着いている!!

development:
adapter: mysql
encoding: utf8
database: accident_development
username: root
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
encoding: utf8
database: accident_test
username: root
password:
socket: /var/lib/mysql/mysql.sock

production:
adapter: mysql
encoding: utf8
database: accident_production
username: root
password:
socket: /var/lib/mysql/mysql.sock

で、usernameとpasswordを修正

$ script/generate model report
$ vi db/migrate/001_create_reports.rb
$ rake migrate

で、

Don't know how to build task 'migrate'

となる。
ググッてみると、Windows版だがdb:migrateとなっているじゃん。

$ rake db:migrate
(in /home/kkijiya/RailsTest/accident)
== 1 CreateReports: migrating =================================================

    • create_table(:reports)

-> 0.7395s
== 1 CreateReports: migrated (0.7410s) ========================================

で、テーブルが作成された。
(ライドオンRailsでは、"db:"がないのはrailsのバージョンの違いのせい?)
とりあえず、今日はここまで。