dI am writing a Model
function that is iterating over a hash, whose keys are named the same as model attribute names. I would like to compare the values of the hash key to the value that is contained in the model attribute of the same name. However, when I generate the attribute name, I do not know how to actually refer to the actual model name and its corrresponding attribute. Currently I am doing the following:
def grade
num_correct = 0
answers = self.class.answers
answers.each do |question, value|
db_question = question
num_correct = num_correct + 1 if db_question.to_i == value
end
if num_correct < 22
return "Beginner"
elsif num_correct >= 22 and num_correct < 41
return "Intermediate"
else
return "Advanced"
end
end
I would like db_question
to actually be the model attribute "db_question", however i am not sure how to make the shift from the simple string which is equivalent to the actual model attribute to the model attribute per se.