I am looking to do the following:
var = 'bank_id'
id = '100'
Bank.where(var: id) or
Bank.where("? = ?", var, id)
Bank is a model. bank_id is an attribute of the model and it is taking it as a string.
Where does accept a hash witch gets mapped to the correct SQL WHERE.
Bank.where(var: id)
is actually
Bank.where({:var => id})
So you can construct your own hash key:
Bank.where({ var.to_s => id })
Or shorter:
Bank.where(var => id)
Just to clarify: The difference actually lies in the different syntax for hash. There are basically two versions.
Always coding has a more detailed explanation.