Reputation: 5682
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
.
Upvotes: 1
Views: 134
Reputation: 99
Assuming you don't have data integrity issues in you staging database (e.g. ends_on isn't being set, you think there should be a renewed policy when there isn't one), you might want to check the system clock and make sure it's both accurate and using the timezone you're expecting.
Upvotes: 2
Reputation: 733
Is policy on a database (and the db differ in your staging and development environment)? In some cases you should format dates in a format more digetible to database, such as Time.now.to_s(:db)
Upvotes: 0