Ruby on rails 3.2 如何打印两列的整数差(Rails 3.2.13)

Ruby on rails 3.2 如何打印两列的整数差(Rails 3.2.13),ruby-on-rails-3.2,Ruby On Rails 3.2,我是RubyonRails的新手。我知道的还不足以寻找答案。如果你恨我,我能理解,但是如果你能在你心里找到扔给我最细小的骨头 这是我的数据库 ActiveRecord::Schema.define(:version=>20130502193545)do create_表“employees”,:force=>true do | t | t.string“名字” t.string“姓氏” t.integer“员工id” t.date“雇用日期” t.datetime“created_at”,:nu

我是RubyonRails的新手。我知道的还不足以寻找答案。如果你恨我,我能理解,但是如果你能在你心里找到扔给我最细小的骨头

这是我的数据库
ActiveRecord::Schema.define(:version=>20130502193545)do
create_表“employees”,:force=>true do | t |

t.string“名字”

t.string“姓氏”

t.integer“员工id”

t.date“雇用日期”

t.datetime“created_at”,:null=>false

t.datetime“updated_at”,:null=>false

t.integer“病假日”

t.integer“休假日”

t.integer“已使用的病假天数”

t.integer“已使用的假期天数”

结束

结束

我只是想弄清楚如何让“病假”和“过去的病假”以及“假期”和“过去的假期”互相交谈。只是一个简单的X-Y方程,这样我就可以在页面上打印出还有多少假期和病假


感谢您对这样一位新手的无限耐心。

您可以在员工模型上添加纯Ruby方法来计算并返回差异

class Employee < ActiveRecord::Base
  def remaining_sick_days
    sick_days - sick_days_used
  end

  def remaining_vacation_days
    vacation_days - vacation_days_used
  end
end
class Employee

当一名员工加载后,您可以使用
@employee获得剩余的休假天数。剩余的休假天数

我没有足够的声誉投票支持您,但谢谢您。这对我有用。对于阅读本文的其他新手,请注意,如果“@”符号位于each块下,则不需要它,在我的例子中,它是“”。那样的话,就写出来打印吧。