2010-07-02 122 views
2

我在Mac OSX 10.6.4上運行ruby,使用Ruby 1.8和activerecord 2.3.8。我運行下面的代碼的NetBeans 6.9的內部,但我使用的是Ruby解釋器從10.6Ruby activerecord似乎忽略set_table_name

我有以下代碼:

require 'rubygems' 
require 'active_record' 

ActiveRecord::Base.establish_connection 
(
    :adapter=> "mysql", 
    :host => "localhost", 
    :username => "test", 
) 

class Test_information < ActiveRecord::Base 
    set_table_name = "test_information" 
end 

record = Test_information.find(:first) 

當代碼運行時我得到一個錯誤,它可以」 t找到表test_informations。有一個名爲test_information的表,我可以查詢它,但不能用activerecord。

是否有一些神奇的咒語,我必須使用set_table_name?我的印象是,使用具有主動記錄的現有模式非常簡單...

任何想法?

由於提前,

--Robert

回答

4

的語法是set_table_name "test_information"(沒有等號)

+0

Doh!支付多想一點... 再次感謝您的幫助。 – RMatthews 2010-07-02 21:23:34

2

set_table_name是一個方法,所以你需要說

set_table_name "test_information" 

通行證作爲參數不作爲轉讓

0

有趣... if在類定義之後,我包含以下兩行中的任何一行。

Test_Information.pluralize_table_names = false 
Test_Information.set_table_name("test_information") 

是有一些原因,它並沒有在類定義內工作?