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 發表於 11:54 PM | 迴響 (0)

November 02, 2006

Ruby on Rails 學習筆記 Part.1

Instant rails 是個 All-in-one 的 RoR 套件
包含了apache、mysql、phpmyadmin 套件
目前僅提供 Windows 下的快速建構
Linux與其他平台則在未來的支援計畫中

到instant rails的官方網站中下載最新版
解壓到C:\的根目錄下(方便好記)就完成了安裝
C:\InstantRails\InstantRails.exe 即為 InstantRails的啟動檔
在 "Agile Web Development With Ruby On Rails" 一書與 Instant Rails 網站中
皆有提到在建構新的 RoR application前
需用 rails "新應用程式的名字"的指令
但InstantRails並沒有幫我們設定好指令的搜尋路徑
因此需要使用者手動在
桌面上的我的電腦->右鍵->內容->進階->環境變數
編輯原有系統變數中的Path
加入;C:\InstantRails\ruby\bin
;是跟其他路徑作區別的分隔符號
重新開機之後就可以在cmd底下使用該指令

C:\InstantRails\rails_apps>rails demo
create
create app/controllers
create app/helpers
create app/models
create app/views/layouts
create config/environments
create components
create db
create doc
create lib
create lib/tasks
create log
create public/images
create public/javascripts
create public/stylesheets
create script/performance
create script/process
create test/fixtures
create test/functional
create test/integration
create test/mocks/development
create test/mocks/test
create test/unit
create vendor
create vendor/plugins
create tmp/sessions
create tmp/sockets
create tmp/cache
create Rakefile
create README
create app/controllers/application.rb
create app/helpers/application_helper.rb
create test/test_helper.rb
create config/database.yml
create config/routes.rb
create public/.htaccess
create config/boot.rb
create config/environment.rb
create config/environments/production.rb
create config/environments/development.rb
create config/environments/test.rb
create script/about
create script/breakpointer
create script/console
create script/destroy
create script/generate
create script/performance/benchmarker
create script/performance/profiler
create script/process/reaper
create script/process/spawner
create script/runner
create script/server
create script/plugin
create public/dispatch.rb
create public/dispatch.cgi
create public/dispatch.fcgi
create public/404.html
create public/500.html
create public/index.html
create public/favicon.ico
create public/robots.txt
create public/images/rails.png
create public/javascripts/prototype.js
create public/javascripts/effects.js
create public/javascripts/dragdrop.js
create public/javascripts/controls.js
create public/javascripts/application.js
create doc/README_FOR_APP
create log/server.log
create log/production.log
create log/development.log
create log/test.log

可以看到 rails 幫我們產生了很多檔案

Reference:
1. http://instantrails.rubyforge.org/tutorial/index.html
2. "Agile Web Development With Ruby On Rails"

本筆記主要是紀錄參考資料中沒有的東西
或是其他想記下來的XD

由 k 發表於 04:56 PM | 迴響 (0)