rails models

一个人想着一个人 提交于 2019-12-12 20:43:06

问题


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"


回答1:


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 

and then calling it like so

@test = MyModule::Test.new


来源:https://stackoverflow.com/questions/974060/rails-models

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!