November 04, 2006

Ruby on Rails 學習筆記 Part.2

在 "Agile Web Development With Ruby On Rails" 一書中 Page 53 提到

If you see the error Before updating scaffolding fromnew DB schema,
try creating a table for your model (Product), it may well be because Ruby (and hence Rails)
can’t get to the database. To fix Apple’s bad install, you’re going to need to reinstall Ruby’s
MySQL library, which means running the script on page 21 to repair the Ruby installation,
and then reinstalling the mysql gem.

但是指 OS X 10.4 才會有
妙的是我用 InstantRails 1.4(all-in-one ,號稱方便與免安裝其他軟體) 也有同樣的狀況= =
要檢視書上範例的網頁 http://localhost:3000/admin 時
會有 lost connection to mysql 的問題
也就是無法連接到 mysql database

問題是在 console 下執行
ruby script/generate scaffold Product Admin
時發生
本來還以為是這書上面的 ruby 版本較舊所造成的問題
就改用 InstantRails 官方網站教學的指令(分為兩步驟)
ruby script\generate model Product
ruby script\generate controller Admin
結果仍舊出現
"error Before updating scaffolding fromnew DB schema,
try creating a table for your model (Product)"

Google後找到解決辦法
不過有點麻煩就是了
下載
http://www.vandomburg.net/files/mysql-ruby-windows-2.7.1.zip
然後解壓縮將 mysql.so copy 到
C:\InstantRails\ruby\lib\ruby\1.8\i386-mswin32

然後再執行上列指令時錯誤就會變成跟 libmysql.dll 有關
Reference 的網站提到 InstantRails 中 php 內附的 libmysql.dll 會無法使用
因此只好下載
http://downloads.mysql.com/archives/mysql-4.1/mysql-4.1.9-win32.zip
然後安裝 mysql-4.1.9 後(InstantRails 幹了啥事竟然還敢說是 all-in-one = =)
覆蓋
C:\Program Files\MySQL\MySQL Server 4.1\lib\libmySQL.dll

C:\InstantRails\ruby\bin
(原本的檔案竟只有106KB,新檔有1.01MB,這也差太多了吧!)

重新啟動 InstantRails
至此 終於可以動了
最後再到控制台去移除Mysql Orz

Reference:
http://www.vandomburg.net/pages/mysql-ruby-windows
這網站有提到一句話
"Getting MySQL/Ruby up and running on Windows used to be a bit of a hassle."
在 Windows 上要可以正常運行 Mysql 與 Ruby 有點小麻煩。
還真是貼切 Orz

由 k 發表於 November 4, 2006 11:54 PM
迴響
發表迴響













記住我的資訊?