我想在模型方法中获取表名。我 found应该有方法 table_name 但是当我尝试调用它时我得到 NameError Exception: undefined local variable or method `table_name'。显然不存在:
pp methods.grep(/^ta.*/)
["table_name_prefix?",
"table_name_suffix?",
"taint",
"taguri",
"taguri=",
"tainted?",
"table_name_prefix",
"table_name_suffix",
"tap"]
如何获得“真实的”表名(无小写 - 复数技巧)?
谢谢
最佳答案
But I need that information in the model's instance method. How to get it?
您可以在实例方法中简单地执行此操作:
class Model
def instance_method
puts Model.table_name
end
end
关于ruby - 如何确定 Rails 3 模型类中的表名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6139640/