0
我有一些模型需要动态初始化。如何使用动态创建的模型调用模型方法
model = <INPUT_STRING>.capitalize.constantize.new
但我不能叫where
方法,通过model.where(~)
它会显示
NoMethodError: undefined method `where' for #<User:0x007fb1142a0978>
我有一些模型需要动态初始化。如何使用动态创建的模型调用模型方法
model = <INPUT_STRING>.capitalize.constantize.new
但我不能叫where
方法,通过model.where(~)
它会显示
NoMethodError: undefined method `where' for #<User:0x007fb1142a0978>
所有你需要不要创建新的对象
model = <INPUT_STRING>.capitalize.constantize
这就是
在您的代码中,model
是User
类的一个实例。删除代码行末尾的new
方法以使其起作用。
您试图在'User'实例上调用'where'而不是class。顺便说一句,你是否以某种方式清理你的输入? –