i have some code that uses a string to determine dynamically what model class to use and for what field to find_by() on. however, i’m having a hard time with how to use these variables to get the model instance. specifically, i have
class Item
include MongoMapper::Document
key :my_variable, String
in my code i have
m = "Item"
f = "my_variable"
and i want to be able to
i = m.find_by_my_variable( f )
result = i[f]
any help is appreciated!
Since you’re in Rails (judging by the category tag) you can use:
to make the string a constant, and then would something like this work for your query?
(EDIT) or use send as ismaelga suggested, if you don’t want an ActiveRecord::Relation array object