[英]How to call model methods with model created dynamically
我有一些模型需要动态初始化。
model = <INPUT_STRING>.capitalize.constantize.new
但我不能调用where
的方法model.where(~)
它会显示
NoMethodError: undefined method `where' for #<User:0x007fb1142a0978>
不创建新对象
model = <INPUT_STRING>.capitalize.constantize
那就是你所需要的
在您的代码中, model
是User
类的实例。 在代码行的末尾删除new
方法,以使其起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.