滑轨型号 [英] rails models

查看:100
本文介绍了滑轨型号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为test.rb的模型,当我在控制器中使用@ tests = Test.new时,出现以下错误.有人可以我怎么解决这个问题吗? "Test:Module的未定义方法'new'"

i have a model named test.rb and when i use @tests=Test.new in my controller i get the following error. Can someone temme how can i resolve this? "undefined method `new' for Test:Module"

推荐答案

如果似乎您的命名冲突,则好像test已经是一个名为Test的模块的名称.尝试将自己的模型放在模块中,即

Looks like test is already the name of a module called Test if would seem that you have naming conflict. Try placing your own model in a module ie

module MyModule
  class Test < ActiveRecord::Base  
  end
end 

然后这样称呼

@test = MyModule::Test.new

这篇关于滑轨型号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆