How to print the integer difference of two columns (Rails 3.2.13) -
i'm very, new @ ruby on rails. don't know enough search answer. understand if hate me if please find in heart throw me teeniest, tiniest bone.
here database
activerecord::schema.define(:version => 20130502193545) do
create_table "employees", :force => true |t|
t.string "first_name"
t.string "last_name"
t.integer "employee_id"
t.date "hire_date"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "sick_days"
t.integer "vacation_days"
t.integer "sick_days_used"
t.integer "vacation_days_used"
end
end
i want figure out how have "sick_days" , "sick_days_used" talk each other, "vacation_days" , "vacation_days_used". simple x - y equation can print on page how many vacation , sick days still available.
thank boundless patience such newbie.
you can add pure ruby methods on employee model calculate , returns differences.
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
when employee loaded can remaining vacations days @employee.remaining_vacation_days
.
Comments
Post a Comment