Ruby中的整数变量不是数字吗?

时间:2018-03-28 20:43:43

标签: ruby-on-rails variables integer numeric

我在user_waiting中将DB个句点保存为整数。我试图在下面的代码中使用它,但我一直收到错误"Expected Numeric."我对Ruby很新,我的理解是整数是数字。我对这种理解不正确吗?

 if @pto_management.waiting_period.nil?
    @pto_management.accrual_begin_date = current_user.start_date
 else
     @pto_management.accrual_begin_date = current_user.start_date + 
                             @pto_management.user_waiting_period
  end

1 个答案:

答案 0 :(得分:0)

或许明确地将其转换为int?

if @pto_management.waiting_period.nil?
  @pto_management.accrual_begin_date = current_user.start_date
else
  @pto_management.accrual_begin_date = current_user.start_date + 
                         @pto_management.user_waiting_period.to_i # <-- HERE
end