title: How would you calculate expiry to update column in rails
body: <p>I'm trying to figure out the right approach for calculating the remainder days of a user subscription.</p>
  
  <p>For example; user signs up December 25, 2013 for a month and unsubscribed December 29, 2013. Even though he unsubscribed 4 days after subscribing, his subscription should run on PLAN A for the next 27 days (31 day based month). </p>
  
  <p>I'm thinking I would be using the created_at and updated_at of subscription model. So far I got to </p>
  
  <p>**MODEL: subscription.rb</p>
  
  <pre><code>class Subscription &lt; ActiveRecord::Base
  
      before_save :set_expiry_date
  
      def set_expiry_date
          @remaining_days = Subscription.calculate(:created_at - Date.today)
          Subscription.expiry = '@remaining_days'
          Subscription.save
      end
  
  end
  </code></pre>
  
  <p>Something like that but I'm missing something here and this might be an ugly approach. I'm guessing this gives anyone who can help small understanding what I'm after.</p>
  
  <p>I would then run a rake as cron each day at 23:59 that removes 1 (day) from Subscription.expiry number in there and when it finds a 0, it would update something. That's another question though but I placed the stuff about the rake cron so you see where I'm heading with this.</p>