2010-07-02 121 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") 

是有一些原因,它并没有在类定义内工作?