我是Teacher payslip控制器,同时使用object获取net_salary显示布尔值而不是其值。获取元素在rails中显示true而不是float值
def payslip_report
if params[:teacher_id] and params[:month_year].present?
@month_and_year = params[:month_year].gsub(' ','')
@teacher_data = TeacherPayslip.where(:teacher_id => params[:teacher_id])
@matched_records = @teacher_data.select{|t| t.salary_date.strftime("%B%Y") == @month_and_year}
#returns an array of TeacherPayslip records with matching month and year
if @matched_records.blank?
raise "2"
else
@report = @matched_records.first
raise @report.net_salary.inspect
end
end
端
在考察@ report.net_salary示出了真实的。 @report包含基本的pf,da,net_salary值。 @pf = @ report.pf的意思是,我会得到pf值。但是,当试图获得net_salary显示布尔值而不是浮点值。
加薪@ report.inspect包含
这里是TeacherPayslip型号
class TeacherPayslip < ActiveRecord::Base
attr_accessible :teacher_id,:salary_date,:hra,:bonus,:pf,:da,
:special_allowance,:basic,:net_salary,:month_year
#associations
belongs_to :teacher
#callbacks
after_create :net_salary
def net_salary
@teacher_id = self.id
@da = (self.basic * self.da)/100
@hra = (self.basic * self.hra)/100
@gs = @da + @hra + self.basic
@pf = (@gs * self.pf)/100
@netsalary = @gs - @pf + self.special_allowance + self.bonus
@a = TeacherPayslip.find(@teacher_id)
#raise @a.inspect
@a.update_attribute('net_salary',@netsalary)
end
end
你能向我们展示你的TeacherPayslip模型吗? – BroiSatse
我已经将TeacherPayslip Model包含在 – user2310209