for example
str_modelname="User"
and i'd like to do
str_modelname.find(:first)
to find first User, but it doesn't work this way of course
for example
str_modelname="User"
and i'd like to do
str_modelname.find(:first)
to find first User, but it doesn't work this way of course
I'm having success with this snippet of code, but I won't claim that it's the best way:
str = "User"
p Kernel.const_get(str).find(:first)
I based this off of this technique.
There are several ways, one of which may be using an hash, like:
models = {"User" => User, "AnotherModel" => AnotherModel}
And then:
models[name] ? models[name].find(:first) : nil
Why do you need this? There could be better solutions, depending on what you need to do.