I’ve got an active record query which is pretty simple
def show
user = User.find(params[:id])
render :text => user.to_json(:include=>:classes)
end
However, in my Class model, I have a method
def self.get_avg_prev_score(id)
return Scores.calc_score(id)
end
I am trying to get the avg_prev_score returned in my JSON hash, but seeing as it isn’t a column in the database, I’m not sure how to do that.
If you’re trying to return an average previous score for each of the classes you’re including, you could do:
and then have your other method return a hash of all scores correlated to the
class_id: