What you need is hash
and not string
. You can use it like this,
hash = {id: 2}
User.where(hash)
And if you really want to use string
you can do it like this,
string = "id = 2"
User.where(string)
If you want to execute the string you can use eval
. In that case it will be like this,
string = "{id: 2}"
User.where(eval string)
1
solved Convert string to XXX