精華區beta Ruby 關於我們 聯絡資訊
出自我的Blog http://lightyror.blogspot.com/2006/10/mapbymethod-irb-bug.html 剛剛發現的問題,我使用的 irbrc 是 強化你的 irb 這裡的設定。我發現到當我 Model 裡面這樣設定 class User < ActiveRecord::Base has_many :habit_contents , :dependent => true has_many :diaries , :dependent => true end 而我在 ruby script/console 裡面使用時,發現到 habit_contents 可以正常使用,但是 diaries 卻會出現 Error 。 >> a = User.find(1) ...... >> a.habit_contents ..... >> >> a.diaries NameError: /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in `const_missing': uninitialized constant Diari 我發現到所有 1:1 使用都沒問題,1:m 有時候有問題。像是 Diaries 無法正確判斷複數,Messages 也無法正確判斷單複數,他會出現 uninitialized constant Messag,很可能是在單複數判斷機制上面出現了 BUG 。 但是我在Web 環境上面,沒有任何的問題,很明顯的,不是我程式的問題,問題出現在 irb 裡面。我想到了上周我改寫了 irbrc ,所以就一行一行檢查。發現到當我將 map_by_method comment 起來,一切都恢復正常了。 require 'rubygems' #require 'map_by_method' require 'what_methods' require 'wirble' require 'irb/completion' So,這明顯是 map_by_method 在 irb 上面的 bug,請暫時不要在 irb 上面使用 map_by_methods 。 -- lighty RoR 是一個介紹 lighttpd , SQLite , Ruby and Rails 的 Blog http://lightyror.blogspot.com/ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.218.90.242