ruby - custom attributes in rails -
i have student model , method calculations , returns value
class student < activerecord::base def total_result #some calculations return result end end
now in students controller following
student.where("total_result > ?", params[:result])
but brings pg::undefinedcolumn: error. using postgres. how achieve this?
you use:
student.select { |student| student.total_result > params[:result] }
a word of warning: load students database , calculate value each of them. slow depending on number of students in table.
if need more make sense store/cache result of calculation in database.
Comments
Post a Comment