gpt4 book ai didi

Ruby activerecord 似乎忽略了 set_table_name

转载 作者:数据小太阳 更新时间:2023-10-29 08:29:22 25 4
gpt4 key购买 nike

我在 Mac OSX 10.6.4 上运行 ruby​​,使用 Ruby 1.8 和 activerecord 2.3.8。我在 NetBeans 6.9 中运行以下代码,但我使用的是 10.6 中的 ruby​​ 解释器

我有以下代码:

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)

当代码运行时,我得到一个错误,它找不到表 test_informations。有一个名为 test_information 的表,我可以查询它...但不能使用 activerecord。

是否有一些我必须与 set_table_name 一起使用的魔法咒语?我的印象是将现有模式与 activerecord 一起使用非常简单......

有什么想法吗?

提前致谢

--罗伯特

最佳答案

语法是set_table_name "test_information"(没有等号)

关于Ruby activerecord 似乎忽略了 set_table_name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3167633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com