1

I have a policy class and in that class I have 2 methods which determin whether or not a customer can renew their policy.

They look like this: (in the policy.rb model)

  def is_renewable?
    if has_not_been_renewed?
       self.ends_on >= Date.today && self.ends_on <= Date.today + 60.days
    end
  end

  def has_not_been_renewed?
    been_renewed = self.renewed_policy.nil? || !self.renewed_policy.active? || !self.active?
  end

So for some reason this is working on my local machine but not in our staging enviroment. (I know right, the bane of every programmer "But it works on my machine!").

The logic seems simple: first check to make sure it hasn't been renewed already or that they have a different active policy. Then check to make sure it hasn't already expired and that it will expire sometime in the next 60 days.

This is called from this line in the view:

<%= link_to('Renew', {:action => 'renew', :id => policy.id}, {:class => 'btn btn-success'}) if policy.is_renewable? %>

I am really failing to see why this wouldn't work anywhere. I wouldn't ask but I have been looking at this stupid problem all day and need a new set of eyes to look it over. Thanks

Incase this helps, the format for both database's (local and staging) is in the form: yyyy-mm-dd so today's date would be 2012-09-06.

4

2 回答 2

2

假设您在暂存数据库中没有数据完整性问题(例如未设置ends_on,您认为没有设置时应该更新策略),您可能需要检查系统时钟并确保它是既准确又使用您期望的时区。

于 2012-09-06T17:13:21.323 回答
0

数据库的策略(并且数据库在您的登台和开发环境中有所不同)?在某些情况下,您应该以更易于数据库理解的格式格式化日期,例如 Time.now.to_s(:db)

于 2012-09-06T17:11:20.490 回答