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

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -