為了與大衆接軌,準備學習RoR,問題不斷中...
唉...
第一次使用RoR,寫個例子時使用[color=red]“rake db:migrate --trace”[/color] ,出錯?;不理這步,頁面上也會出現[color=red]“undefined method `each' for #<Mysql:0x36fbd20>”[/color] 。
RoR的配置如下:
C:\ror_work\depot>gem list
*** LOCAL GEMS ***
actionmailer (2.1.0)
actionpack (2.1.0)
activerecord (2.1.0)
activeresource (2.1.0)
activesupport (2.1.0)
fxri (0.3.6)
fxruby (1.6.12)
hpricot (0.6)
log4r (1.0.5)
mislav-will_paginate (2.3.2)
mysql (2.7.3)
rails (2.1.0)
rake (0.8.1)
rubygems-update (1.2.0)
sources (0.0.1)
win32-api (1.0.4)
win32-clipboard (0.4.3)
win32-dir (0.3.2)
win32-eventlog (0.4.6)
win32-file (0.5.4)
win32-file-stat (1.2.7)
win32-process (0.5.3)
win32-sapi (0.1.4)
win32-sound (0.4.1)
windows-api (0.2.0)
windows-pr (0.7.2)
日志檔案如下:
C:\ror_work\depot>rake db:migrate --trace
(in C:/ror_work/depot)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
[color=red]undefined method `each' for #<Mysql:0x36fbd20> [/color]
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_a
dapters/mysql_adapter.rb:403:in `tables'
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_a
dapters/abstract/schema_statements.rb:324:in `initialize_schema_migrations_table
'
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb
:387:in `initialize'
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb
:357:in `new'
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb
:357:in `up'
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb
:340:in `migrate'
d:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:99
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_c
hain'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_c
hain'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:in `invoke_task'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exceptio
n_handling'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exceptio
n_handling'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run'
d:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.1/bin/rake:31
d:/ruby/bin/rake:19:in `load'
d:/ruby/bin/rake:19
我的資料庫MySql6.0.5和MySql5.0.51b
看到老外也有同樣的問題,這個貌似是個答案.
[color=red]
This problem can be caused by an a mismatch between versions of the
mySQL gem and the version of mySQL. If you are using version 2.7.3 of
the mySQL driver, make sure you upgrade your mySQL installation to
5.0.27 from 5.0.24 - that can fix the problem (worked for me...)
[/color]
有很多人說5.0.24不行,更新就行了,可是最新的5.0.51b我也試過了,問題仍然存在...
蒼天啊,答案居然是這個?!
http://sweetriver.spaces.live.com/blog/cns!367370eb9a9b2807!444.entry
我從“\MySQL Tools for 5.0\”下拷了一個[color=red]“libmysql.dll”[/color] ,放在“\ruby\bin\”目錄下就解決了.....