I have some models need to be initialized dynamically.
model = <INPUT_STRING>.capitalize.constantize.new
But I can not call where
method by model.where(~)
It will show
NoMethodError: undefined method `where' for #<User:0x007fb1142a0978>
Do not create new object
model = <INPUT_STRING>.capitalize.constantize
thats all you need
In your code, model
is an instance of the User
class. Remove the new
method at the end of your line of code to get it to work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.